首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Chrome webdriver不会从cron打开

Chrome webdriver不会从cron打开
EN

Stack Overflow用户
提问于 2016-11-14 10:01:19
回答 1查看 463关注 0票数 2

我在Python2.7中运行了一个BeautifulSoup & Selenium脚本,它在终端上运行得很好,但不会作为cron作业运行。

我得到以下回溯:

代码语言:javascript
复制
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语句,如下所示:

代码语言:javascript
复制
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')

有人能就这个问题提出建议吗。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-12 19:19:21

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40586043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档