2015-09-10 22 views
6

Quindi ho difficoltà a far funzionare il selenio con un driver headless, in particolare PhantomJS. Sto cercando di farlo funzionare su un server web Ubuntu (Ubuntu 14.04.2 LTS).Selenium Python Headless Webdriver (PhantomJS) non funziona

eseguendo i seguenti comandi da un interprete python (Python 2.7.6) dà:

from selenium import webdriver 
driver = webdriver.PhantomJS() 

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__ 
    self.service.start() 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/service.py", line 76, in start 
    raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e) 
selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghostdriver: [Errno 2] No such file or directory 

Ho anche provato:

driver = webdriver.PhantomJS(executable_path="/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/") 

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__ 
    self.service.start() 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/service.py", line 76, in start 
    raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e) 
selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghostdriver: [Errno 13] Permission denied 

Ho anche aggiunto al percorso pitone:

import sys 
sys.path.append("/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/") 

Sono attualmente connesso come root. Autorizzazioni per la directory phantomjs sono:

drwxr-sr-x 2 root staff 4096 Sep 9 06:58 phantomjs 

e per phantomjs/webdriver.py:

-rw-r--r-- 1 root root 2985 Sep 9 06:58 webdriver.py 

Ho confermato il selenio è installato e up-to-date (PIP installare il selenio --upgrade) . Si è installato in:

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/ 

print selenium.__version__ 
2.47.1 

Ho guardato:

Ho testato il mio programma su un server localmente ospitato (su OSX), utilizzando chromedriver. In realtà sto usando Splinter (https://splinter.readthedocs.org/en/latest/#headless-drivers) per quello, e ho provato gli altri driver headless (django e zope.testbrowser) ma ho avuto problemi simili.

Sono aperto a qualsiasi suggerimento, non mi dispiace cambiare driver se necessario.

Grazie in anticipo per qualsiasi aiuto.

risposta

12

Ho avuto lo stesso problema con gli stessi errori. Ho provato ad installarlo su OpenSuse Server. Ho finito per installare l'origine del modulo PhantomJS, purtroppo senza alcun successo.Il modo in cui ha lavorato per me stava installando Phantomjs via npm

sudo npm install -g phantomjs 
+0

Funzionava anche su Mac OSX. – vaichidrewar

+0

Grazie per il suggerimento. Questo ha funzionato anche per me. – cdfh

+0

Ho risolto la mia domanda usando Linux Mint – rafaelcpalmeida

3

Così l'installazione phantomjs attraverso il gestore dei pacchetti sembrava risolvere il problema ...

sudo apt-get install phantomjs 

In ogni caso speriamo che il processo di cui sopra aiuta altre persone che hanno lo stesso problema.

+0

Per le persone che hanno il problema su OSX Yosemite, mi è stato sempre il seguente errore: 'selenium.common.exceptions.WebDriverException: Messaggio: Impossibile connettersi a GhostDriver sulla porta XXXX' Quale è stato collegato all'errore 'Killed: 9' quando si esegue' phantomjs' dal terminale. Questi collegamenti lo hanno risolto per me: http://stackoverflow.com/questions/28267809/phantomjs-getting-killed-9-for-anything-im-trying https://github.com/eugene1g/phantomjs/ releases – cdfh

Problemi correlati