我想从span id“hkoTemp”中获取文本
这是代码:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim wb As WebBrowser = New WebBrowser
wb.Navigate(New Uri("http://www.hko.gov.hk/contentc.htm"))
Dim temp = wb.Document.GetElementById("hkoTemp").GetAttribute("innerText")
MsgBox(temp)
End Sub
当我尝试运行它时,它会出现错误
Dim temp = wb.Document.GetElementById("hkoTemp").GetAttribute("innerText")
我该如何解决?
答案 0 :(得分:0)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim wb As WebBrowser = New WebBrowser()
wb.AllowNavigation = True
AddHandler wb.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf wb_DocumentCompleted)
wb.Navigate(New Uri("http://www.hko.gov.hk/contentc.htm"))
End Sub
Private Sub wb_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
' wb.Document is not null at this point
Dim wb As WebBrowser = sender
Dim temp = wb.Document.GetElementById("hkoTemp").GetAttribute("innerText")
MsgBox(temp)
End Sub