我试图从网页中获取特定字段,这是我的代码:
Dim htmlDocument As New HtmlDocument
Const node As String = "//*[@id='table_menu_right']/tbody/tr[1]/td/table[3]/tbody/tr[2]/td/table/tbody/tr[3]/td/p[1]"
Dim webReq As System.Net.WebRequest = System.Net.WebRequest.Create("http://dof.gob.mx")
Dim webRes As System.Net.WebResponse = webReq.GetResponse()
Dim mystream As System.IO.Stream = webRes.GetResponseStream()
If mystream IsNot Nothing Then
Dim myHtmlDoc As New HtmlDocument()
myHtmlDoc.Load(mystream)
Dim nodo As HtmlNode = htmlDocument.DocumentNode.SelectSingleNode(node)
但我在下一行得到 Null:
Dim tipoCambio As String = nodo.InnerText
txtTipoDeCambio.Text = tipoCambio
End If
我已经尝试过使用本地 html 文件,我得到了我想要的方式,但是当我使用 WebRequest 时,我得到了 Null。
有谁知道我怎么能正确地做到这一点?
谢谢!