我正在使用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
答案 0 :(得分:4)
像这样:
If link.Attributes("href") IsNot Nothing Then