在解析网页时,当我在本地运行时,以下功能正常工作:
Public Function GetElement(ByVal IHTMLDOMNode As mshtml.IHTMLDOMNode, ByVal InnerText As String) As mshtml.IHTMLElement
Dim objIHTMLAnchorElement As mshtml.HTMLAnchorElementClass
Dim s As String
s = Microsoft.VisualBasic.Information.TypeName(IHTMLDOMNode)
If s = "HTMLAnchorElementClass" Then
t = GetType(mshtml.HTMLAnchorElementClass)
objIHTMLAnchorElement = Marshal.CreateWrapperOfType(IHTMLDOMNode, t)
If objIHTMLAnchorElement.innerText.Trim() = InnerText Then
Return objIHTMLAnchorElement
End If
End if
' code that loks at child nodes and makes a recursive call
但是,当它部署在Web主机提供程序时,相同的输入会导致字符串s为“HTMLAnchorElement”而不是“HTMLAnchorElementClass”。
如果我将代码更改为
Dim objIHTMLAnchorElement As mshtml.HTMLAnchorElement
Dim s As String
s = Microsoft.VisualBasic.Information.TypeName(IHTMLDOMNode)
If s = "HTMLAnchorElement" Then
t = GetType(mshtml.HTMLAnchorElement)
objIHTMLAnchorElement = Marshal.CreateWrapperOfType(IHTMLDOMNode, t)
If objIHTMLAnchorElement.innerText.Trim() = InnerText Then
Return objIHTMLAnchorElement
End If
End if
我得到一个“类型必须是__ComObject或从__ComObject派生”错误
这种行为可能是什么原因和/或我该怎么办?
答案 0 :(得分:0)
如果不理解为什么(有人请详细说明),以下工作:
Dim objIHTMLAnchorElement As mshtml.HTMLAnchorElement
Dim s As String
s = Microsoft.VisualBasic.Information.TypeName(IHTMLDOMNode)
If s = "HTMLAnchorElement" Then
t = GetType(mshtml.HTMLAnchorElementClass)
objIHTMLAnchorElement = Marshal.CreateWrapperOfType(IHTMLDOMNode, t)
If objIHTMLAnchorElement.innerText.Trim() = InnerText Then
Return objIHTMLAnchorElement
End If
End if