在VB.Net中使用HtmlAlityPack检查元素是否具有特定属性
我正在使用HtmlAgilityPack解析HTML 我想检查元素是否具有特定属性在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(
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
是什么。我在这里发布了这个问题