试试这个,它帮助我用 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
UPD:深入了解 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