【发布时间】:2017-03-27 22:20:27
【问题描述】:
我有一个在 Python 2.7 中运行的 BeautifulSoup 和 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')
任何人都可以就这个问题提出建议。
【问题讨论】:
-
但是当我在 crontab -e 下运行它时它对我有用,所以我必须在我的系统上而不是在我的客户的系统上提供它。如何设置?
-
@e4c5 很抱歉,但我不明白为什么这意味着当我输入它时它可以在我的系统上运行,但它不能在我客户的系统上运行。我显然对 cron 缺乏了解,但是当我使用 crontab -e 进入工作时,它可以在我的服务器上运行。然后设置时
-
它正在创建上面显示的回溯错误,而在我的系统上,脚本运行并完成其任务
-
但是当我使用 crontab -e 输入它时它确实有效。也许你可以指点我一个很好的入门书
-
你能用最新版本的chromedriver再试一次吗?我曾经遇到过类似的问题,就是这样解决的。
标签: python selenium cron beautifulsoup