为什么此代码不会返回通用列表中的任何 ID。网页在 div 元素中肯定有 id。如果我断点它,则属性Id
中没有 idDocumentNode.SelectNodes
并且htmlDoc.DocumentNode.SelectNodes("//div[@id]")
不起作用。我正在使用 .NET 2.0 和 HtmlAgilityPack.dll 1.4.0.0。
Imports HtmlAgilityPack
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim listHtmlFound As List(Of String) = New List(Of String)
Dim webGet As HtmlWeb = New HtmlWeb
Dim htmlDoc As HtmlDocument = webGet.Load("http://stackoverflow.com/q/11528387/1350308")
htmlDoc.OptionUseIdAttribute = True
'Dim s As Object = htmlDoc.DocumentNode.SelectNodes("//div/@id").Count
For Each div As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//div")
listHtmlFound.Add(div.Id)
Next
End Sub
End Class