2017-01-22 67 views
1

我正在遠程服務器上運行Python腳本,該腳本定期使用PhantomJS作爲Selenium中的webdriver進行網頁捕獲。PhantomJS webdriver錯誤代碼-6

腳本停止運行了一段時間,拋出下面的錯誤後意外:

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錯誤(因此參數)的事,但它似乎並不相關我認爲。

關於導致此問題的原因的任何想法?

回答

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解決這個問題。