Extracting a table with Html Agility Pack

html html-agility-pack vb.net web-scraping

Question

I am trying to extract a table from a webpage using Html Agility Pack. So far I have managed to do a little of progress with it. This is my code so far

    Dim web As New HtmlAgilityPack.HtmlWeb()
    Dim htmlDoc As HtmlAgilityPack.HtmlDocument = web.Load("--Website url--")
    Dim html As String = htmlDoc.DocumentNode.OuterHtml

    Dim tabletag = htmlDoc.DocumentNode.SelectNodes("//table")

Basically I need to find a table with the following html tag

     <table width="100%"  border="0" cellspacing="0" cellpadding="3" summary="Contains search results">

Any Idea how I can strip down my search for tables to that specific table ?

1
1
7/10/2012 11:09:44 AM

Accepted Answer

You need to determine what it is about the table that makes it unique among all the tables in the document. It may be one of those attributes of the table, such as the summary attribute that makes it unique. Or, it may be one of its child elements inside the table that you need to look for. Since you didn't specify, I'll show an example of how to limit the results based on the summary attribute:

Dim tabletag = htmlDoc.DocumentNode.SelectNodes("//table[@summary='Contains search results']")
2
7/10/2012 12:22:53 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow