Hi @Malik Asad Mahmood ,
You need to know how to get specific table with Html Agility Pack.
Take a look at the following code:
...
Dim lstName As List(Of String) = New List(Of String)
Dim dt As DataTable = New DataTable
For Each table As HtmlNode In doc.DocumentNode.SelectNodes("//table[contains(@id,'earningsHistory')]")
For Each columnNameNode As HtmlNode In table.SelectNodes(".//tr/th")
Dim columnName As String = columnNameNode.InnerText
If columnName.Contains(" ") Then
Dim name = columnName.Replace(" ", " ")
lstName(lstName.Count - 1) += name
Else
lstName.Add(columnName)
End If
Next
For Each colName As String In lstName
dt.Columns.Add(colName)
Next
Dim i As Integer
Dim row As DataRow = dt.NewRow()
For Each itemNode As HtmlNode In table.SelectNodes(".//tr/td")
If i = dt.Columns.Count Then
i = 0
dt.Rows.Add(row)
row = dt.NewRow()
End If
If itemNode.InnerText.Contains(" ") Then
row(i) += itemNode.InnerText
Else
row(i) = itemNode.InnerText
i += 1
End If
Next
Next
DataGridView1.DataSource = dt
Result of my test:
Best Regards,
Xingyu Zhao
*
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.