【发布时间】:2011-05-30 17:49:21
【问题描述】:
我正在使用 HtmlAgilityPack 来解析 HTML。
我想检查一个元素是否具有特定属性。
我想检查<a>标签是否有href属性。
Dim doc As HtmlDocument = New HtmlDocument()
doc.Load(New StringReader(content))
Dim root As HtmlNode = doc.DocumentNode
Dim anchorTags As New List(Of String)
For Each link As HtmlNode In root.SelectNodes("//a")
If link.HasAttributes("href") Then doSomething() 'this doesn't work because hasAttributes only checks whether an element has attributes or not
Next
【问题讨论】:
-
我在我的程序中使用完全相同的代码,并且在 foreach 行中出现错误
Object reference not set to an instance of an object. -
@Smith:不要使用我的代码,而是使用 Slaks 的固定代码
标签: vb.net html-parsing html-agility-pack