python – 使用PhantomJs拒绝连接

我在
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)

比在周期中我要求使用以下页面:

self.driver.get('page-url')

一切都很好用了大约5分钟(约2分钟内完成),之后我得到错误:

 <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

一切都在本地机器上运行.

最佳答案 当加载图像被禁用时,似乎问题出现在
memory leak of PhantomJS

'phantomjs.page.settings.loadImages' : False

所以当我启用图像时,加载问题就消失了.

点赞