PhantomJS webdriver错误代码-6

时间:2017-01-22 16:33:50

标签: python selenium web-scraping phantomjs

我在远程服务器上运行Python脚本,定期擦除网页,使用PhantomJS作为Selenium中的webdriver。

脚本在运行几个小时后意外停止,引发以下错误:

Traceback (most recent call last):
  File "long.py", line 74, in <module>
    data = scrape_page_long()
  File "long.py", line 19, in scrape_page_long
    driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 96, in start
    self.assert_process_still_running()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
    % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: -6 

我一开始认为它与ssl错误(因此参数)有关,但我认为它看起来并不相关。

有关导致此问题的原因的任何想法?

1 个答案:

答案 0 :(得分:4)

您的脚本永远无法抓取网页,因为PhantomJS根本无法在服务器上运行。

如果您登录服务器并运行phantomjs --version,您会看到:

QXcbConnection: Could not connect to display
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
Aborted

您可以通过将export QT_QPA_PLATFORM=offscreen添加到您的用户帐户.bashrc,或将QT_QPA_PLATFORM=offscreen添加到服务器的/etc/environment来解决此问题。< / p>