【问题标题】:Connection refused using PhantomJs使用 PhantomJs 拒绝连接
【发布时间】:2015-11-27 06:41:21
【问题描述】:

我在 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 分钟(约 1 分钟内 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

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

【问题讨论】:

    标签: python selenium phantomjs


    【解决方案1】:

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

    'phantomjs.page.settings.loadImages' : False
    

    所以当我启用图片加载问题就消失了。

    【讨论】:

      猜你喜欢
      • 2016-03-12
      • 1970-01-01
      • 2017-08-08
      • 2019-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多