使用PhantomJs拒绝连接

2024-04-20 08:06:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python中使用Selenium+PhantomJS驱动程序。它的配置如下:

desired_cap = {
        'phantomjs.page.settings.loadImages' : False,
        'phantomjs.page.settings.resourceTimeout' : 10000,
        'phantomjs.page.settings.userAgent' : '...'
}

self.driver = webdriver.PhantomJS(desired_capabilities=desired_cap)

self.driver.set_window_size(1024, 768)
self.driver.set_page_load_timeout(10)

而不是在循环中,我请求一些页面使用:

^{pr2}$

每样东西都能正常工作大约5分钟(2秒钟内约1次),之后我收到错误:

 <urlopen error [Errno 111] Connection refused>

它不仅出现在get方法中,而且出现在从self.driver调用的任何方法中。我认为与phantomjs实例的连接由于某种原因而断开,对象无法向其发送命令。在

phantomjs --version
2.0.1-development

uname -a
Linux wincode 3.16.0-38-generic #52~14.04.1-Ubuntu SMP Fri May 8 09:43:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

一切都在本地计算机上运行。在


Tags: 方法selfsettingslinuxdriverselenium驱动程序page