Running phantomJS from script in cronjob

I am running a python script through cronjob. I have a virtual environment, and in cronjob I run it through this virtual environment. When I run the script, usually phantomJS starts as it should, but when I run it through the script in cronjob, I get this error. What is missing in cronjob to be able to run phantomjs?

Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen Traceback (most recent call last): File "/home/scraper/superfish-extension/chrome_3day.py", line 96, in <module> main() File "/home/scraper/superfish-extension/chrome_3day.py", line 73, in main browser = use_phantomjs() File "/home/scraper/superfish-extension/chrome.py", line 81, in use_phantomjs browser = webdriver.PhantomJS() File "/home/scraper/.virtualenvs/superfish/lib/python2.6/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 50, in __init__ self.service.start() File "/home/scraper/.virtualenvs/superfish/lib/python2.6/site-packages/selenium/webdriver/phantomjs/service.py", line 69, in start raise WebDriverException("Unable to start phantomjs with ghostdriver.", e) WebDriverException: Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen 
+6
source share
3 answers

Since phantom is probably installed in /usr/local/bin , you should add this directory to PATH in your crontab. The following should do the trick:

 SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 
+12
source

As an alternative to the accepted answer, you can add the following line in the 1st line of crontab:

 PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs 

which indicates the path to PhantomJS before running cron tasks.

+3
source

which helped:

 #!/bin/bash export DISPLAY=:0 /usr/bin/phantomjs /home/pi/test.js 
+1
source

Source: https://habr.com/ru/post/970835/


All Articles