Quantcast
Channel: htmlagilitypack Forum Rss Feed
Viewing all articles
Browse latest Browse all 655

New Post: Extracting a table from a page

$
0
0

Here's one way to do it. I like to use Linq, but you can do it other ways. This shows loading the document from a file, but again, you can do it other ways. I didn't compile it, so apologies in advance if you need to tweak it a bit to get it right! But hopefully it'll give you a push in the right direction.

 

    HtmlDocument htmlDoc = new HtmlDocument();
    htmlDoc.Load( "foo.html" );

    if ( htmlDoc.DocumentNode != null ) {
        var tableNode = ( from node in htmlDoc.DocumentNode.Descendants()
                         where node.Name == "table"
                         where node.Attributes.Contains( "summary" )
                         where node.Attributes["summary"].Value == "Contains search results"
                         select node ).FirstOrDefault();
                                     
        if ( tableNode != null ) {
            // Work with table node here
        }
    }

 


Viewing all articles
Browse latest Browse all 655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>