In VB.Net, use HtmlAgilityPack to check whether an element contains a certain attribute.

html-agility-pack html-parsing vb.net

Question

To parse HTML, I'm using HtmlAgilityPack.

If an element has a certain property, I want to make sure it does.

I want to determine whether an<a> Tagged is thehref attribute.

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
1
3
12/25/2010 10:55:57 PM

Accepted Answer

akin to this

If link.Attributes("href") IsNot Nothing Then
4
4/8/2015 2:50:33 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow