我想使用crontab运行此脚本:
#!/usr/bin/ python
from pyvirtualdisplay import Display
from selenium import webdriver
def main():
with Display(visible=False, size=(1200, 1500)):
browser = webdriver.Firefox()
browser.get("http://www.python.org")
print browser.title
browser.close()
if __name__ == "__main__":main()
使用此crontab命令:
* * * * * export DISPLAY=:0 && /usr/bin/python /home/me/test.py
但是python给了我这个例外:
Traceback (most recent call last):
File "/home/me/test.py", line 13, in <module>
main()
File "/home/me/test.py", line 7, in main
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox /webdriver.py", line 148, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
当我尝试在终端中执行它时没有任何问题,它给了我一个结果:
Welcome to Python.org
也许你有任何解决方案?谢谢!