我正在通过cronjob运行python脚本。我有一个虚拟环境,在cronjob中,我正在通过这个虚拟环境运行它。当我运行脚本时,通常phantomJS应该启动它,但是通过cronjob中的脚本运行它我得到了这个错误。 cronjob中缺少什么才能启动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
答案 0 :(得分:14)
由于幻像可能安装在/usr/local/bin
中,您应该将该目录添加到crontab中的PATH
。以下应该可以解决问题:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
答案 1 :(得分:4)
作为接受答案的替代方法,您可以在crontab的第1行添加以下行:
PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs
指定运行cron任务之前PhantomJS的路径。
答案 2 :(得分:1)
为我做了诀窍:
#!/bin/bash
export DISPLAY=:0
/usr/bin/phantomjs /home/pi/test.js