使用VB.Net中的HtmlAgilityPack检查元素是否具有特定属性

html-agility-pack html-parsing vb.net

我正在使用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

一般承认的答案

喜欢这个:

If link.Attributes("href") IsNot Nothing Then


Related

许可下: CC-BY-SA with attribution
不隶属于 Stack Overflow
许可下: CC-BY-SA with attribution
不隶属于 Stack Overflow