2014-06-14 16 views
6

Tôi đang chạy tập lệnh python thông qua cronjob. Tôi có một môi trường ảo và trong cronjob tôi đang chạy nó thông qua môi trường ảo này. Khi tôi chạy script thường thì phantomJS bắt đầu như nó cần, nhưng chạy nó thông qua một script trong cronjob tôi nhận được lỗi này. Điều gì là thiếu trong cronjob để có thể bắt đầu ảo?Bắt đầu phantomJS từ tập lệnh trong cronjob

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 

Trả lời

12

Như phantom có ​​lẽ được cài đặt trong /usr/local/bin, bạn nên thêm rằng dir để PATH trong crontab của bạn. Sau đây nên làm như lừa:

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

Để thay thế cho câu trả lời được chấp nhận, bạn có thể thêm dòng sau vào dòng 1 của crontab:

PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs 

trong đó xác định con đường của PhantomJS trước khi chạy cron nhiệm vụ.

1

rằng đã làm các trick cho tôi:

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

Tại sao mã chỉ này trả lời làm việc? Cần giải thích – ppperry

Các vấn đề liên quan