documentnode selectsinglenode vb.net code example

Example: documentnode selectsinglenode vb.net

Dim webClient As WebClient = New WebClient()         Dim page As String = webClient.DownloadString("https://www.psx.com.pk/market-summary/")         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").SelectSingleNode("h4").InnerText             Console.WriteLine(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)                 End If             Next             lstTable.Add(dt)         Next