【问题标题】:VB.net InternetExplorer HtmlDocumentVB.net InternetExplorer HtmlDocument
【发布时间】:2013-12-09 04:53:12
【问题描述】:

有人可以帮助我吗?我是 VB.net 的新手,并尝试编写一个非常简单的代码来操作网站。但是,我不断得到

“发生了“System.InvalidCastException”类型的未处理异常 在 Defer All.exe .... 无法转换类型的 COM 对象 'System.__ComObject' 到接口类型'mshtml.HTMLDocument'。这个 操作失败,因为 COM 组件上的 QueryInterface 调用 对于具有 IID '....) 的接口。”

        Dim IE As InternetExplorer
        Dim HTMLDoc As HtmlDocument
        Dim oHTML_Element As mshtml.IHTMLElement
        IE = new InternetExplorer
        IE.Navigate("http://www.mediafire.com/")
        Do Until IE.ReadyState = 4
        Loop
        Loop Until Not IE.Busy
        ' ERROR on the following line
        HTMLDoc = IE.Document
        ' I tried making HTMLDoc as object. It passed the above line, but failed the next line due to no GetElementsByTagName method
        For Each oHTML_Element In HTMLDoc.GetElementsByTagName("input")
          '....................
        Next

【问题讨论】:

  • 您必须等待浏览器真正导航到该页面。在此之前,Document 属性可能为 null - 或其他类型的不确定。
  • 你想处理 DocumentCompleted 事件。
  • 谢谢丹欧。对不起,我编辑了我的帖子。我确实等到一切都完成了。似乎 IE.Document 是一个 com.object 并且不能转换为 HTMLDocument。我不知道为什么它不起作用。它适用于 VBA。

标签: vb.net


【解决方案1】:

改变...

Dim IE As InternetExplorer
Dim HTMLDoc As HtmlDocument
'                    ^---------------------------this thing to,
                                                 mshtml.IHTMLDocument
Dim oHTML_Element As mshtml.IHTMLElement

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-16
    • 2012-06-24
    • 2012-09-14
    • 1970-01-01
    • 2012-10-08
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    相关资源
    最近更新 更多