我有一个BeautifulSoup&在Python 2.7中运行的Selenium脚本,可以从终端完美运行,但不会作为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行,它开始失败的地方是下面的with语句:
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 :(得分:0)
我的解决方案最终是切换到firefox并实现pyvirtualdisplay来模仿显示。