Use the
Event DocumentCompleted()
of the WebBrowser, instead of the Form Load() Event.
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
TextBox1.Text = WebBrowser1.Document.GetElementById("infobox-number").InnerText
MsgBox("DOCUMENT_COMPLETED")
End Sub
... but i noticed that the DocumentCompleted() Event raised dozens of times, also when i scrolled up&down.
Here i give some code that i used years ago on my project. It does not use the WebBrowser, instead it downloads the data directly. Try to tweak it for your needs.
Private Function GetInfo() As String
dim body as string = ""
Try
Dim ur As New Uri("http://www.find-ip-address.org/")
Dim req As HttpWebRequest = CType(HttpWebRequest.Create(ur), HttpWebRequest)
Dim res As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
If (res.StatusCode = HttpStatusCode.OK) Then
Dim receiveStream As Stream = res.GetResponseStream()
Dim readStream As StreamReader = Nothing
If (res.CharacterSet = Nothing) Then
readStream = New StreamReader(receiveStream)
Else
readStream = New StreamReader(receiveStream, Encoding.GetEncoding(res.CharacterSet))
Dim data As String = readStream.ReadToEnd()
res.Close()
readStream.Close()
Dim left = "My IP Country Name:"
Dim right = "IP Address Lookup Location"
Dim indexLeft As Integer = data.IndexOf(left)
Dim indexRight As Integer = data.IndexOf(right)
body = data.Substring(indexLeft + left.Length, indexRight - indexLeft - left.Length)
End If
End If
End Try
Return body
End Function