问题描述
我正在通过 cronjob 运行 python 脚本.我有一个虚拟环境,在 cronjob 中,我通过这个虚拟环境运行它.当我正常运行脚本时,phantomJS 会正常启动,但是通过 cronjob 中的脚本运行它时出现此错误.cronjob 中缺少什么才能启动 phantomjs?
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
推荐答案
由于 phantom 可能安装在 /usr/local/bin
中,您应该将该目录添加到 PATH
> 在您的 crontab 中.以下应该可以解决问题:
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
这篇关于从 cronjob 中的脚本启动 phantomJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!