无法使用createDocumentFromUrl获取html元素 [英] Can't fetch html element using createDocumentFromUrl

查看:129
本文介绍了无法使用createDocumentFromUrl获取html元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 createDocumentFromUrl()直接在vba中从网页获取 HTMLDocument?我做了很多尝试以找到SO上的任何文档,但没有找到。希望有人伸出援助之手来实现这一目标。提前致谢。

How can I use "createDocumentFromUrl()" to fetch "HTMLDocument" from a webpage directly in vba? I tried a lot to reach out any documentation on it in SO but failed to find out. Hope there is somebody to stretch a helping hand to accomplish this. Thanks in advance.

这是我到目前为止尝试过的,绝对不正确:

Here is what I've tried so far which is definitely not right:

Sub HtmlScraper()
    Dim odoc As Object
    Set odoc = New HTMLDocument

    odoc.Open createDocumentFromUrl("http://www.stackoverflow.com", "null")
    MsgBox odoc.body.innerHTML
End Sub

I也尝试过这样,但是没有运气:

I tried like this as well but no luck:

Sub htmlparser()
    Dim odoc As HTMLDocument, hdoc As HTMLDocument

    Set odoc = New HTMLDocument
    Set hdoc = New HTMLDocument

    Set hdoc = odoc.createDocumentFromUrl("http://www.stackoverflow.com", Null, False)
    MsgBox hdoc.body.outerHTML
End Sub


推荐答案

这对我有用,可能是网站。

This worked for me, it may be the site.

Sub test()

Dim d As MSHTML.HTMLDocument
Set d = New MSHTML.HTMLDocument
Dim d2 As MSHTML.HTMLDocument

set d2=d.createDocumentFromUrl("www.bbc.co.uk", "null")

While d.readyState <> "complete"
    DoEvents
Wend

End Sub

这篇关于无法使用createDocumentFromUrl获取html元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆