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 ?

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']")


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why