internet-explorer - Failproof 等待 IE 加载

标签 internet-explorer web-scraping vbscript wsh readystate

脚本是否有一种万无一失的方法可以等到 Internet Explorer 完全加载?

两者 oIE.Busy和/或 oIE.ReadyState没有按照他们应该的方式工作:

Set oIE = CreateObject("InternetExplorer.application")

    oIE.Visible = True
    oIE.navigate ("http://technopedia.com")

    Do While oIE.Busy Or oIE.ReadyState <> 4: WScript.Sleep 100: Loop  

    ' <<<<< OR >>>>>>

    Do While oIE.ReadyState <> 4: WScript.Sleep 100: Loop

还有其他建议吗?

最佳答案

试试这个,它帮助我解决了一次与 IE 类似的问题:

Set oIE = CreateObject("InternetExplorer.application")
oIE.Visible = True
oIE.navigate ("http://technopedia.com")
Do While oIE.ReadyState = 4: WScript.Sleep 100: Loop
Do While oIE.ReadyState <> 4: WScript.Sleep 100: Loop
' example ref to DOM
MsgBox oIE.Document.GetElementsByTagName("div").Length

更新:深入研究 IE 事件,我发现 IE_DocumentComplete是页面实际准备好之前的最后一个事件。因此,还有一种方法可以检测网页何时加载(请注意,您必须指定可能与目标 URL 不同的确切目标 URL,例如在重定向的情况下):
option explicit
dim ie, targurl, desturl, completed

set ie = wscript.createobject("internetexplorer.application", "ie_")
ie.visible = true

targurl = "http://technopedia.com/"
desturl = "http://technopedia.com/"

' targurl = "http://tumblr.com/"
' desturl = "https://www.tumblr.com/" ' redirection if you are not login
' desturl = "https://www.tumblr.com/dashboard" ' redirection if you are login

completed = false
ie.navigate targurl
do until completed
    wscript.sleep 100
loop
' your code here
msgbox ie.document.getelementsbytagname("*").length
ie.quit

sub ie_documentcomplete(byval pdisp, byval url)
    if url = desturl then completed = true
end sub

关于internet-explorer - Failproof 等待 IE 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23299134/

相关文章:

python - 使用 urlretrieve() 下载文件到子文件夹

windows - VBScript - 相对路径不起作用

vbscript - 如何使用 GUI 脚本读取 GuiTree 控件的行详细信息

internet-explorer - 对象不支持此属性或方法

javascript - 等待光标在 IE10 中不显示

flash - 为什么 IE 中的 Z-Index 不按照 Flash 电影应有的方式呈现?

html - IE 中的 CSS 圆 Angular

python - 如何使用Scrapy进行多页面抓取?

javascript - 如何检查网站是否有 javascript?

vbscript - 为什么我收到“找不到路径”错误?