Hi ,
Please I need help to read html table (EPS earning table) from following URL
https://www.investing.com/equities/wrldcal-teleco-earnings and insert into datatable my code as following its connecting and return data from investing as I have zero knowledge in htmlaglibitypack using.
my code as follows
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Using client As New WebClient()
client.Headers.Add("user-agent", "karen payne")
ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
ServicePointManager.DefaultConnectionLimit = 9999
Dim page As String = client.DownloadString(siteAddress)
' TextBox1.Text = htmlCode
' Dim page As String = WebClient.DownloadString("https://www.investing.com/equities/wrldcal-teleco")
Dim doc As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument()
doc.LoadHtml(page)
Dim lstNode As List(Of HtmlNode) = New List(Of HtmlNode)
Dim lstName As List(Of String) = New List(Of String)
Dim lstTable As List(Of DataTable) = New List(Of DataTable)
For Each thed As HtmlNode In doc.DocumentNode.SelectNodes("//thead")
lstNode.Add(thed.ParentNode)
Dim text = thed.SelectSingleNode("tr").SelectSingleNode("th").InnerText
' Console.WriteLine(text)
MsgBox(text)
MsgBox(text)
lstName.Add(text)
Next
For i As Integer = 0 To lstNode.Count - 1
Dim dt As DataTable = New DataTable
dt.TableName = lstName(i)
For Each trNode As HtmlNode In lstNode(i).SelectNodes("tr")
If trNode.Attributes("class") Is Nothing Then
For Each colNode As HtmlNode In trNode.SelectNodes("td")
dt.Columns.Add(colNode.InnerText)
Next
Else
Dim j As Integer = 0
Dim row As DataRow = dt.NewRow()
For Each rowNode As HtmlNode In trNode.SelectNodes("td")
row(j) = rowNode.InnerText
j += 1
Next
dt.Rows.Add(row)
' MsgBox("test")
End If
Next
lstTable.Add(dt)
DataGridView1.DataSource = dt
Next
End Using
MsgBox("final finished...")
End Sub