【发布时间】:2019-09-10 22:30:54
【问题描述】:
我正在使用 selenium 网络驱动程序加载页面。但是页面正在无限加载。 我试图捕捉异常并模拟 esc 键操作,但这没有帮助。由于某些限制,我只能使用 Firefox [我已经看到了 chrome add on 解决方案]。一旦我点击页面,我就无法恢复控制。
我将我的 Firefox 配置文件设置为
firefoxProfile = FirefoxProfile()
firefoxProfile.set_preference('permissions.default.stylesheet', 2)
firefoxProfile.set_preference('permissions.default.image', 2)
firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so','false')
firefoxProfile.set_preference("http.response.timeout", 10)
firefoxProfile.set_preference("dom.max_script_run_time", 10)
停止加载的脚本:
try:
driver.set_page_load_timeout(10)
driver.get('http://www.example.com'
except Exception
print 'time out'
driver.send_keys(Keys.CONTROL +'Escape')
【问题讨论】:
-
你能分享你使用的实际网址吗?
-
这是我公司的项目,所以我不能公开分享网址。这会造成不必要的问题。
-
好的,我明白了,您根本不会设置个人资料偏好?它仍然永远加载吗?另外,您是否尝试过等待 30 多秒?
-
如果我没有设置任何 Firefox 配置文件,它会正确加载,但问题是页面有超过 100 个大尺寸图像。这使得加载过程非常慢。所以我想禁用图像.
-
您好,感谢您的建议。然而,它并没有帮助停止页面加载。但是,如果我尝试应用 x-path 来提取异常块中的内容,而是试图停止页面加载,我可以获得我想要的内容,即使页面仍在加载。所以我正在应用 x-paths 来提取内容并关闭该窗口。