簡體   English   中英

chromedriver 不再運行,因此 ChromeDriver 假設 Chrome 使用 Selenium 到 Python 發生崩潰錯誤

[英]chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed error using Selenium through Python

在我開始之前:我知道有十億個關於 Selenium 不起作用的帖子,以及各種嘗試的解決方案。 我相信我已經嘗試了一切,但如果我遺漏了什么,請原諒我。 我的頭撞在牆上,希望得到幫助。

以下是我采取的一些步驟:

我下載了 selenium(Ubuntu,Python)的 chromedriver,並使用chmod 755chmod 777使驅動程序可執行。 之后,我用 ./chromedriver 啟動了./chromedriver

我嘗試了 Selenium 的各種選項,包括手動添加運行 chromedriver 的端口

from selenium import webdriver

options = webdriver.ChromeOptions()
options.binary_location = "/home/myname/projects/myproject/chromedriver"
options.add_argument("--remote-debugging-port=9515")
chrome_driver_binary = '/home/myname/projects/myproject/chromedriver'
driver = webdriver.Chrome(chrome_driver_binary, options = options)
driver.get('http://www.ubuntu.com/')

我已經嘗試過其他帖子中建議的選項,例如:

options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--disable-setuid-sandbox")

我確保我使用的是與我的 Chrome 版本兼容的 chromedriver。

似乎沒有任何效果。 我不斷收到此錯誤:

WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (chrome not reachable)
  (The process started from chrome location /home/myname/projects/myproject/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

我真誠地感謝別人對這個問題的解釋。

您需要注意以下幾點:

  • options.binary_location :指的是二進制位置,如果Google Chrome未安裝在默認位置,則使用該位置。 請參閱: WebDriverException:未知錯誤:對於舊版本的 Google Chrome,在 Python 中找不到帶有 Selenium 的 Chrome 二進制錯誤

  • --remote-debugging-port :如果您不是遠程調試,則可以安全地刪除此參數。

  • chrome_driver_binary :指ChromeDriver在系統中的絕對位置。

  • webdriver.Chrome(chrome_driver_binary, options = options) :此外,您可能希望添加key executable_path ,如下所示:

     chrome_driver_binary = '/home/myname/projects/myproject/chromedriver' driver = webdriver.Chrome(executable_path=chrome_driver_binary, options = options) driver.get('http://www.ubuntu.com/')
  • --no-sandbox--headless--disable-dev-shm-usage--disable-setuid-sandbox等是您可能不需要啟動的可選設置。

啟動Selenium驅動的ChromeDriver啟動瀏覽上下文的最小代碼塊可以是:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(executable_path='/home/myname/projects/myproject/chromedriver', options=options)
driver.get("http://www.ubuntu.com/")


參考

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

暫無
暫無

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM