本文介绍了htmlagilitypack选择所有节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码

i have this code

Dim htmldoc As HtmlDocument = New HtmlDocument()
htmldoc.LoadHtml(strPageContent)
Dim root As HtmlNode = htmldoc.DocumentNode

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



但出现错误 Object reference not set to an instance of an object.

该文档包含至少一个锚标签?如何检查属性是否存在?

我尝试了这个link.HasAttributes("title")并遇到了另一个错误

Public ReadOnly Property HasAttributes() As Boolean'' has no parameters and its return type cannot be indexed.

Thanks



but am getting an error Object reference not set to an instance of an object.

the document contains at least one anchor-tag? how do i check if an attribute exits?

i tried this link.HasAttributes("title") and get another error

Public ReadOnly Property HasAttributes() As Boolean'' has no parameters and its return type cannot be indexed.

thanks

推荐答案


这篇关于htmlagilitypack选择所有节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 23:02