running phantomjs inside python virtualenv for sel

2019-07-13 03:49发布

问题:

I am on OSX

I need to use PhantomJS in a Python#3.5 scrapper running with selenium. I wrote a working program without setting a virtual environnement first. It works fine, but now I started building a virtual environnement with virtualenv and copied my code inside the newly created environnement. Everything is working fine... But PhantomJs and Firefox.

I specified the path to phantomJS

driver = webdriver.PhantomJS(executable_path=r'/Users/Me/.npm-packages/bin/phantomjs')

I get :

selenium.common.exceptions.WebDriverException: Message: Service /Users/Me/.npm-packages/bin/phantomjs unexpectedly exited. Status code was: 127

I decided to try and install a nodeenv environnement inside my virtualenv.

I activated my virtualenv and did :

pip install nodeenv

Then:

nodeenv -p

returns an [SSL: CERTIFICATE_VERIFY_FAILED] error...

so I launched a new terminal window, and used a global nodeenv to install my node environnement :

nodeenv Path/To/MyVirtualEnv/MyNodeEnv

I then activated my NodeEnv environnement

Path/To/MyVirtualEnv/MyNodeEnv
. bin/activate

I installed PhantomJs:

npm install phantomjs

'Which phantomjs' still returns my globally installed phantomjs

I specified a new path to phantomJS anyway :

driver = webdriver.PhantomJS(executable_path=r'/Path/To/MyVirtualEnv/MyNodeEnv/node_modules/phantomjs/bin/phantomjs')

... and I get the same error :

selenium.common.exceptions.WebDriverException: Message: Service /Users/PierreEligny/Documents/PRO/peecks_bot/nodeenv/node_modules/phantomjs/bin/phantomjs unexpectedly exited. Status code was: 127

I am stuck. Do you have any ideas what I could do or did wrong ? Thanks.