【发布时间】:2015-08-18 12:59:54
【问题描述】:
我正在尝试将状态请求自动发送到工作中的第三方供应商网站。目前,我让我的脚本在每次操作后等待 40 秒以等待页面加载。 (在最坏的情况下,加载时间从 1 秒到几分钟不等)。
有没有办法让我的脚本在继续之前等待 IE 完成加载?
我尝试了代码IELoad(wb)from here,但它并不总是有效。 (有时它会坐在那里,我必须按 F5)。昨晚我让它跑了,它停了大约 25 箱。
观察:页面将被加载,但IELoad(wb) 函数仍在等待。
; You need to send the IE handle to the function unless you define it as global.
IELoad(wb) {
If !wb ;If wb is not a valid pointer then quit
Return False
Loop ;Otherwise sleep for .1 seconds untill the page starts loading
Sleep,100
Until (wb.busy)
Loop ;Once it starts loading wait until completes
Sleep,100
Until (!wb.busy)
Loop ;optional check to wait for the page to completely load
Sleep,500
Until (wb.Document.Readystate = "Complete")
Return True
}
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("www.someVendor.com")
IELoad(wb)
; This is the part I have the most problems with
wb.document.getElementById("someLink").click()
; The page might be loaded, but it will sit there and wait forever
IELoad(wb)
; Do some clicking and searching...
【问题讨论】:
-
我用 AHK 做了很多浏览器自动化,你的脚本看起来还不错。您可以尝试使用
wb.Document.Body.innerHTML查看加载的页面,并在单击之前进行一些检查。就我个人而言,我离开 AHK 是为了实现网络自动化,现在使用免费工具 Selenium(你可能想用谷歌搜索一下),它在包含大量 javascript 的网站上效果更好。 -
在第二次阅读时,如果按 F5 可以解决您的问题,您还可以运行一个计时器,该计时器每 10 秒按一次 F5,并在 IELoad 命令之前激活该计时器并在之后停用它...
-
您也可以尝试复制按钮执行的 HTTP 请求,而不是在呈现的环境中执行点击。它需要对 HTML 和可能的 JavaScript 进行一些逆向工程,但它会运行得更加可靠、高效和流畅。如果您有兴趣,我已经创建了一个关于如何使用 AHK 完成的小指南:stackoverflow.com/questions/29458900/…
-
相关:How do I wait for Google Chrome to load a webpage before continuing in AutoHotkey?(这些答案中的大多数也适用于 IE)
标签: internet-explorer autohotkey