Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting phantomJS from a script in a cronjob

I'm running a python script through a cronjob. I have a virtual environment and in the cronjob I'm running it through this virtual environment. When I run the script normally phantomJS starts as it should, but running it through a script in a cronjob I get this error. What is missing in the cronjob to be able to start 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
like image 680
Jonathan Avatar asked Jun 14 '14 11:06

Jonathan


2 Answers

As phantom is probably installed in /usr/local/bin, you should add that dir 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
like image 79
Artjom B. Avatar answered Oct 26 '22 05:10

Artjom B.


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

PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs

which specifies the path of PhantomJS before running cron tasks.

like image 4
Raptor Avatar answered Oct 26 '22 05:10

Raptor