1
I’m trying to get the value inside a <table>
, because it needed to get the value within a <tr>
that is inside the table.
I’ve tried it a few ways, but the one I’m using null
.
In fact I ended up after a few attempts I got more or less what I wanted
but with this code he lists them all
I’m actually trying to get the longitude and latidude values
This is the part 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. 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