下面是我的代码片段:
Dim content As String = ""
Dim web As New HtmlAgilityPack.HtmlWeb
Dim doc As New HtmlAgilityPack.HtmlDocument()
doc.Load(WebBrowser1.DocumentStream)
Dim hnc As HtmlAgilityPack.HtmlNodeCollection = doc.DocumentNode.SelectNodes("//div[@class='address']/preceding-sibling::h3[@class='listingTitleLine']")
For Each link As HtmlAgilityPack.HtmlNode In hnc
Dim replaceUnwanted As String = ""
replaceUnwanted = link.InnerText.Replace("&", "&") '
<span style="white-space:pre"> </span> content &= replaceUnwanted & vbNewLine
Next
'I have a bunch of code here I removed ------------------------------
Dim htmlDoc As HtmlDocument = Me.WebBrowser2.Document
Dim visibleHtmlElements As HtmlElementCollection = htmlDoc.GetElementsByTagName("TD")
Dim found As Boolean = False
For Each str As HtmlElement In visibleHtmlElements
If Not String.IsNullOrEmpty(str.InnerText) Then
Dim text As String = str.InnerText
If str.InnerText.Contains(parts(2)) Then
found = True
End If
End If
Next我得到了Me.WebBrowser2.Document的一个错误
“不能将'System.Windows.Forms.HtmlDocument‘类型的值转换为'HtmlAgilityPack.HtmlDocument’。
htmlDoc.GetElementsByTagName的另一张
'GetElementsByTagName‘不是'HtmlAgilityPack.HtmlDocument’的成员。
当我不使用HAP时,代码可以工作,但是我需要导入它来做一些事情,现在它会干扰这一点。请帮帮忙。
发布于 2010-09-13 01:02:24
问题是,HtmlAgilityPack和System.Windows.Forms都有一个名为HtmlDocument的类型。
您可能只需修复这一行:
' Here the VB compiler must think you mean HtmlAgilityPack.HtmlDocument: '
Dim htmlDoc As HtmlDocument...by将其更改为:
Dim htmlDoc As System.Windows.Forms.HtmlDocument通常,解决此类问题的一个好方法是使用Imports语句为名称冲突的类型提供别名,如下所示:
Imports AgilityDocument = HtmlAgilityPack.HtmlDocument
Imports FormsDocument = System.Windows.Forms.HtmlDocument然后,您将在代码中使用这些别名之一,而不是键入共享名称。因此,例如:
Dim doc As New AgilityDocument
Dim htmlDoc As FormsDocument = Me.WebBrowser2.Documenthttps://stackoverflow.com/questions/3697291
复制相似问题