gpt4 book ai didi

internet-explorer - Failproof 等待 IE 加载

转载 作者:行者123 更新时间:2023-12-04 11:52:22 25 4
gpt4 key购买 nike

脚本是否有一种万无一失的方法可以等到 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com