2016-11-14 93 views
1

我有一个BeautifulSoup & Selenium脚本运行在Python 2.7中,它可以从终端完美工作,但不会作为cron作业运行。Chrome webdriver无法从cron打开

我得到以下回溯:

Traceback (most recent call last): 
File "sel_hourly.py", line 50, in <module> 
with closing(Chrome(chrome_options=options)) as driver: 
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__ 
desired_capabilities=desired_capabilities) 
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__ 
self.start_session(desired_capabilities, browser_profile) 
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session 
response = self.execute(Command.NEW_SESSION, capabilities) 
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute 
self.error_handler.check_response(response) 
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response 
raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally 
(Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 4.8.0-22-generic x86_64) 

50号线,在那里开始的失败是在下面的语句:

options = webdriver.ChromeOptions() 
options.add_argument("--start-maximized") 
with closing(Chrome(chrome_options=options)) as driver: 
    driver.get(url) 
    # wait for the page to load 
    time.sleep(1) 
    # store it to string variable 
    page_source = driver.page_source 
    soup = bs4.BeautifulSoup(page_source,'lxml') 

任何人都可以提出建议的问题。

+0

但是,当我在crontab -e下运行它时,它适用于我,所以我必须在系统上给它,而不是在我的客户上。我如何设置它? – HenryM

+0

@ e4c5我很抱歉,但我不明白为什么这意味着它会在我的系统上工作,当我输入它但它不能在我的客户系统上运行。我明显缺乏对cron的理解,但是当我使用crontab -e输入作业时,它在我的服务器上运行。然后设置 – HenryM

+0

它创建上面显示的回溯错误,而在我的系统上脚本运行并完成其任务 – HenryM

回答

0

我最终的解决方案是切换到firefox并实现pyvirtualdisplay来模仿显示。