簡體   English   中英

WebDriverException:消息:未知錯誤:Chrome 無法啟動:通過 VPS 上的 Python 使用 ChromeDriver Chrome 和 Selenium 異常退出

[英]WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium through Python on VPS

所以我有與這些帖子完全相同的錯誤

Selenium 'Chrome 啟動失敗:異常退出'錯誤

未知錯誤:Chrome 無法啟動:異常退出

我嘗試了他們推薦的方法,但沒有奏效。

這是我的代碼

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 上運行它。

這個錯誤信息...

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

Google 團隊首次將Headless Chrome作為GA(通用可用性)發布時,文章Getting Started with Headless Chrome提到:

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

添加了一個注釋:

現在,如果您在 Windows 上運行,您還需要包含--disable-gpu標志。

根據討論Headless: make --disable-gpu flag 不必要,很明顯:

LinuxMac OSX上不再需要--disable-gpu標志。 一旦錯誤SwiftShader 在無頭模式下的 Windows 上斷言修復,它也將在 Windows 上變得不必要。 現在,由於此問題已標記為已修復,因此參數--disable-gpu現在應該是多余的。

注意:您可以在ERROR:gpu_process_transport_factory.cc(1007)-Lost UI shared context 中找到詳細討論:在 Headless 模式下通過 ChromeDriver 初始化 Chrome 瀏覽器時


但是,您的主要問題是您使用的二進制文件版本之間的不兼容,如下所示:

支持Chrome v58-60

  • 我們不知道您的chrome版本。 假設您使用的是以下任一版本的最新Chrome版本:
    • Chrome version 71
    • Chrome version 72
    • Chrome version 73

所以ChromeDriver v2.30Chrome 瀏覽器 v71-73之間存在明顯的不匹配

解決方案

  • 根據您的Chrome 瀏覽器版本,按照以下 指南相應地升級ChromeDriver
    • 如果您使用的是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 ,請參閱此討論了解支持它的ChromeDriver版本。

參考

您可以在以下位置找到一些相關討論:

您尚未提供瀏覽器的版本,但 chromedriver 2.30 已經舊了 - 大約 2017 年 6 月; Chrome 當時是 59 版,現在是 72 版。 是的,我查過了,我不是很清楚他們的發布歷史😀

我建議將其升級到最新版本 - 或升級到與您安裝的瀏覽器相匹配的版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 WebDriverException:消息:未知錯誤:Chrome 無法啟動:通過 WebDriverManager 使用 Selenium ChromeDriver 和 Chrome 異常退出 WebDriverException:消息:未知錯誤:Chrome 無法啟動:使用 ChromeDriver Chrome 和 Selenium Python 異常退出錯誤 selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome無法啟動:使用ChromeDriver Chrome和Selenium異常退出 WebDriverException:消息:未知錯誤:Chrome 無法啟動:在 debian 服務器上使用 ChromeDriver Chrome 和 Selenium 異常退出 設置 selenium 與 headless chrome 錯誤:WebDriverException:消息:未知錯誤:Chrome 無法啟動:異常退出 Python:Selenium-消息:未知錯誤:Chrome無法啟動:異常退出 WebDriverException:消息:未知錯誤:Chrome 無法啟動:在 Amazon Linux 上通過 Selenium Python 使用 ChromeDriver Chrome 出現崩潰錯誤 TDD-Django(部署)錯誤:selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome無法啟動:異常退出 selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome 無法啟動:異常退出。 Dockerize Flask 應用程序 selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome 無法啟動:在 Python 中使用 ChromeDriver 和 Selenium 崩潰
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM