从一个tomphanjs脚本开始工作

2024-09-30 12:25:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在通过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

Tags: toinpy脚本homewithlinephantomjs
3条回答

这对我来说很有意思:

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

由于幻影可能安装在/usr/local/bin中,所以您应该将该目录添加到crontab中的PATH。下面的方法可以做到:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

作为接受答案的替代方法,您可以在crontab的第一行添加以下行:

PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs

它指定在运行cron任务之前PhantomJS的路径。在

相关问题 更多 >

    热门问题