【发布时间】:2011-06-06 13:05:12
【问题描述】:
我有这个代码
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.
文档至少包含一个锚标记?如何检查属性是否存在?
我试过这个if link.HasAttributes("title") then 并得到另一个错误
Public ReadOnly Property HasAttributes() As Boolean' has no parameters and its return type cannot be indexed.
【问题讨论】: