【发布时间】:2017-06-20 20:46:01
【问题描述】:
尝试在 Linux 下生成 webdriver 有点困难。
我在 CentOS 7.3 上安装了 Chrome、Chromium 和许多其他 python 库。我在跑步:
chrome_options = webdriver.ChromeOptions()
thechromedriver = webdriver.Chrome(executable_path='/home/skyscraper/chromedriver', chrome_options=chrome_options)
具有不同路径的替代方案在 Windows 下运行良好,所以问题肯定出在我的 Linux 端口上。
我跑过:
chmod a+x chromedriver
它在 root 下运行,因此它应该可以访问 chromedriver。
如果我通过超时的线程池生成它,它每次都会达到该超时。正常运行它最终会抛出错误:
Traceback (most recent call last):
File "Skyscrapercomp.py", line 492, in <module>
thechromedriver = webdriver.Chrome(executable_path='/home/skyscraper/chromedriver', chrome_options=chrome_options)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/lib/python2.7/site-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.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 3.10.0-514.2.2.el7.x86_64 x86_64)
我的收获是“Chrome 无法启动:异常退出”,这并没有给我太多继续。
我使用 pip 安装了最新的 Selenium 和 Yum 来安装 Chromium 和 Chrome。感觉有点死在水中,不确定我的下一步是什么,所以我真的很感激朝着正确的方向前进。
/更新:
我检查了 /usr/bin google-chrome 是否在那里,这是它想要的默认位置。
还尝试将 chromedriver 放入 /usr/bin 并且不给它一个位置:
TheBrowser = webdriver.Chrome()
TheBrowser.get("http://www.google.com")
print TheBrowser.page_source.encode('utf-8')
但这给出了同样的错误。
【问题讨论】:
-
您是尝试以交互方式运行它,还是设置了 xvfb?
-
只要 Selenium 可以访问它,对我来说并不重要。我会设置 xvfb 并尝试这种方式。
-
这可能是个问题:如果 Chrome 驱动程序没有显示,它会像这样失败。所以是的,尝试设置适当的 xvfb 解决方案,至少您将消除导致此错误的一个常见原因。
标签: python linux python-2.7 google-chrome selenium