0

在解析网页时,以下函数在我本地运行时可以正常工作:

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”错误

这种行为的原因可能是什么和/或我能做些什么?

4

1 回答 1

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
于 2013-09-19T06:03:46.937 回答