Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VB.Net中使用HtmlAlityPack检查元素是否具有特定属性_Vb.net_Html Parsing_Html Agility Pack - Fatal编程技术网

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

在VB.Net中使用HtmlAlityPack检查元素是否具有特定属性,vb.net,html-parsing,html-agility-pack,Vb.net,Html Parsing,Html Agility Pack,我正在使用HtmlAgilityPack解析HTML 我想检查元素是否具有特定属性 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(

我正在使用HtmlAgilityPack解析HTML

我想检查元素是否具有特定属性

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
我想检查
标记是否具有
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

我在程序中使用了完全相同的代码,我在foreach行
对象引用中得到一个错误,没有设置为对象的实例。
@Smith:不要使用我的代码,而是使用Slaks的固定代码。你能帮我处理我在上面的评论中得到的错误吗?你需要找出
null
是什么。我在这里发布了这个问题