WebDriverException:消息:未知错误:Chrome无法启动:在VPS上通过Python使用ChromeDriver Chrome和Selenium异常退出

问题描述 投票:1回答:2

所以我和这些帖子有完全相同的错误

Selenium 'Chrome failed to start: exited abnormally' error

Unknown error: Chrome failed to start: exited abnormally

我尝试了他们推荐的东西而且没有用。

这是我的代码

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))
display.start()

options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-extensions')
options.add_argument('--headless')
options.add_argument('--disable-gpu')

driver = webdriver.Chrome(chrome_options=options)
driver.get('http://nytimes.com')
print(driver.title)

driver.close()

这是完整的错误消息

Traceback (most recent call last):
  File "seleniumtest.py", line 13, in <module>
    driver = webdriver.Chrome(chrome_options=options)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, 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.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.15.0-42-generic x86_64)

我做错了什么恶魔?我在digitalocean上的ubuntu VPS上运行它。

python selenium google-chrome selenium-chromedriver google-chrome-headless
2个回答
-1
投票

此错误消息...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.15.0-42-generic x86_64)

...暗示ChromeDriver无法启动/生成新的WebBrowser,即Chrome浏览器会话。

正好有两个不兼容问题,如下所述。


禁用-GPU

当Headless Chrome首次由Google Team作为GA(一般可用性)发布时,文章Getting Started with Headless Chrome提到:

--disable-gpu \                # Temporarily needed if running on Windows.

添加了一条注释:

现在,如果你在Windows上运行,你还需要包含--disable-gpu标志。

根据讨论Headless: make --disable-gpu flag unnecessary,很明显:

在Linux或Mac OSX上不再需要--disable-gpu标志。一旦bug SwiftShader fails an assert on Windows in headless mode被修复,它也将在Windows上变得不必要。现在,当这个问题被标记为固定时,参数--disable-gpu现在应该是多余的。

注意:您可以在ERROR:gpu_process_transport_factory.cc(1007)-Lost UI shared context : while initializing Chrome browser through ChromeDriver in Headless mode中找到详细的讨论


但是,您的主要问题是您使用的二进制文件版本之间的不兼容性如下:

  • 您正在使用chromedriver = 2.30
  • chromedriver=2.30的发行说明明确提到以下内容:

支持Chrome v58-60

  • 您的chrome版本对我们来说不了解。假设您正在使用最新的Chrome版本: Chrome version 71 Chrome version 72 Chrome version 73

因此ChromeDriver v2.30与Chrome浏览器v71-73之间存在明显的不匹配

  • 根据您的Chrome浏览器版本升级ChromeDriver,请遵循以下guidelines: 如果您使用的是Chrome 73版,则需要下载ChromeDriver 73.0.3683.20 如果您使用的是Chrome版本72,则需要下载ChromeDriver 2.46或ChromeDriver 72.0.3626.69 如果您使用的是Chrome版本71,则需要下载ChromeDriver 2.46或ChromeDriver 71.0.3578.137 对于较旧版本的Chrome,请参阅this discussion以获取支持它的ChromeDriver版本。

0
投票

您没有提供浏览器的版本,但是chromedriver 2.30已经很老了 - 大约在2017年6月; Chrome当时是版本59,现在是72。 (yes, I checked, it's not like I know their release history by heart 😀

我建议将其升级到最新版本 - 或者将其升级到与您安装的浏览器匹配的版本。

© www.soinside.com 2019 - 2024. All rights reserved.