I'm trying to get the value inside a <table>
because I needed to get the value inside a <tr>
that is inside the table.
I've tried it in some ways, but the one I'm using gives me null
value.
In fact I ended up after a few attempts I got more or less what I wanted
but with this code it lists the td how can i separate them
in fact I'm trying to take the values of longitude and latidude
This was the part that I changed
Public Function getele()
Dim bodytext As Windows.Forms.HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("td")
For Each Tag As HtmlElement In bodytext
ListBox1.Items.Add(Tag.InnerText)
'MessageBox.Show(Tag.InnerText)
If Tag = Nothing Then
MsgBox("")
End If
Next
End Function
This is the code on the page I look for a way to extract only longitude and latitude only. Country: Portugal State / Region: Faro District Latitude: 37.2887925 (37 ° 17 '19.65 "N) Longitude: -8.5930041 (8 ° 35 '34.81 "W)
This is my code:
Imports System.Text.RegularExpressions
Imports System.Net
Imports System.IO
Public Class Form9
Dim Col As HtmlElementCollection
Dim Ele As HtmlElement
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'GetExternalIP()
WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("https://whatismyipaddress.com/ip/2001:8a0:7594:5401:a9da:74f8:9ecb:38bb")
WaitForPageLoad()
getele()
ListBox1.Items.Add(WebBrowser1.Document.GetElementById("table").InnerText())
End Sub
Private Shared Function GetExternalIP() As String
Dim Response As String = String.Empty
Try
Dim myWebClient As New System.Net.WebClient
Dim whatIsMyIp As String = "http://automation.whatismyip.com/n09230945.asp"
Dim file As New System.IO.StreamReader(myWebClient.OpenRead(whatIsMyIp))
Response = file.ReadToEnd()
file.Close()
file.Dispose()
myWebClient.Dispose()
Catch ex As Exception
Response = "Could not confirm External IP Address" & vbCrLf & ex.Message.ToString
End Try
Return Response
End Function
Private Sub getViews()
Try
Dim version = FileVersionInfo.GetVersionInfo("c:\windows\system32\ieframe.dll")
'Depending on the navigator version, google's server sends diffetent pages, so
'Here Detect ie version
If version.ProductVersion < "8" Then
lb_views.Text = WebBrowser1.Document.GetElementById("th").FirstChild.InnerText
Else
lb_views.Text = WebBrowser1.Document.GetElementById("td").FirstChild.InnerText
End If
Catch ex As Exception
MsgBox(ex.ToString)
Application.Exit()
End Try
End Sub
Private Property pageready As Boolean = False
Private Sub WaitForPageLoad()
AddHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
While Not pageready
Application.DoEvents()
End While
pageready = False
End Sub
Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
pageready = True
RemoveHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
End If
End Sub
Public Function getele()
Dim elementList As HtmlElementCollection
Dim curElement As HtmlElement
elementList = WebBrowser1.Document.GetElementsByTagName("a")
For Each curElement In elementList
'You can use the innerText attribute to locate the hyperlink
If curElement.GetAttribute("innerText").Equals("Latitude:") Then
lb_views.Text = curElement.ToString
curElement.InvokeMember("click")
End If
'Or use the innerHtml attribute
If curElement.GetAttribute("innerHtml").Contains("<th>Latitude:</th>") Then
curElement.InvokeMember("click")
lb_views2.Text = curElement.ToString
End If
Next
End Function
End Class