I'm trying to grab a data table from a webpage and display it in a vb.NET application.
While doing some research I found out that the HTML Agility Pack contains features that will allow to easily scrape/extract data from a webpage.
The pack does not contain any documentation and I can't seem to find the right solution on the internet. Hope someone could push me in the right direction.
This is the table I'm trying to pull.
http://testapplications.net16.net/test.html[
^]
This is what I found while browsing the net and trying different methods:
' Load the html document
Dim web As New HtmlWeb()
Dim doc As HtmlDocument = web.Load("http://testapplications.net16.net/test.html")
' Get all tables in the document
Dim tables As HtmlNodeCollection = doc.DocumentNode.SelectNodes("/table")
' Iterate all rows in the first table
Dim rows As HtmlNodeCollection = tables(0).SelectNodes("./tr")
For i As Integer = 0 To rows.Count - 1
' Iterate all columns in this row
Dim cols As HtmlNodeCollection = rows(i).SelectNodes("./td")
For j As Integer = 0 To cols.Count - 1
' Get the value of the column and print it
Dim value As String = cols(j).InnerText
MessageBox.Show(value)
Next
Next
I get a NullReference error at the following line:
Dim rows As HtmlNodeCollection = tables(0).SelectNodes("./tr")
Object reference not set to an instance of an object.
I'm guessing this means that TR can't be found within the code of the table?
What I have tried:
Browsed the web for documentation or solutions for my problem, couldn't find any articles or tutorials.