如何设置PhantomJS的超时时间? [英] How to set timeout for PhantomJS?

查看:917
本文介绍了如何设置PhantomJS的超时时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用来设置它的代码:

Here's the code I have for setting it:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.resourceTimeout"] = ("5000")
driver = webdriver.PhantomJS(desired_capabilities=dcap)

但是在我的超长脚本中,当我的互联网速度很慢并且页面加载时间超过5秒时,似乎并没有超时.

However in my super long script, it doesn't seem to timeout when my internet is slow and a page takes longer than 5 seconds to load.

关于PhantomJS超时的文档很少,而有关Python的文档则更少,所以我认为这甚至不是解决问题的方法.

There is so little documentation on PhantomJS time outs, and even less of it is for Python, so I figure maybe this isn't even the way to do it.

有人用Python中的PhantomJS成功设置了超时时间吗?

Has anyone successfully set a timeout with PhantomJS in Python?

谢谢!

推荐答案

您可以像下面的Firefox驱动程序示例那样为Driver设置超时,而不是针对phantomjs资源超时:

instead of targeting phantomjs resource timeout, you can set a timeout for Driver like below example of Firefox driver:

browser = webdriver.Firefox()
browser.set_page_load_timeout(30)

您可以将30更改为任意数字

you can change 30 to any numeric

谢谢

这篇关于如何设置PhantomJS的超时时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆