开发者

Check if element has a specific attribute using HtmlAgilityPack in VB.Net

开发者 https://www.devze.com 2023-02-01 08:42 出处:网络
I\'m using HtmlAgilityPack to parse HTML. I want to check if an element has a specific attribute. I want to check whether an <a> tag has the href attribute.

I'm using HtmlAgilityPack to parse HTML.

I want to check if an element has a specific attribute.

I want to check whether an <a> tag has the href attribute.

Dim doc As HtmlDocument = New HtmlDocument()

d开发者_开发技巧oc.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


Like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消