我使用asp.net vb从跨域网页检索html
Dim objWebClient As New WebClient()
objWebClient.UseDefaultCredentials = True
objWebClient.Headers.Add(HttpRequestHeader.UserAgent, "XPlorer")
'STEP 2: Call the DownloadedData method
Const strURL As String = "http://www.example.com"
Dim aRequestedHTML() As Byte
aRequestedHTML = objWebClient.DownloadData(strURL)
'STEP 3: Convert the Byte array into a String
Dim objUTF8 As New UTF8Encoding()
Dim strRequestedHTML As String
strRequestedHTML = objUTF8.GetString(aRequestedHTML)
另外,我想在文字控件中只展示它的一部分。作为一个例子,我想只显示带有“结果”类的表。
如何在VB.NET中使用XML和XQuery进一步处理?如何将strRequestedHTML声明为XML以及如何在其中进行xquery?
事先提前......答案 0 :(得分:0)
如果您谈论网页(html),最好将其解析为HTML而不是XML。 Html Agility Pack是一个很好的.NET开源HTML解析器
您也可以使用Html Agility Pack下载网页。
类似的东西:
Dim htmlWeb As HtmlAgilityPack.HtmlWeb = New HtmlWeb()
Dim htmlDocument As HtmlAgilityPack.HtmlDocument = htmlWeb.Load("http://www.google.com")
Dim htmlNode As HtmlAgilityPack.HtmlNode = htmlDocument.DocumentNode.SelectSingleNode("//table[@class='result']")
Response.Write(htmlNode)