問題描述
這是我的代碼腳本:
從 selenium 導入 webdriver選項 = webdriver.ChromeOptions()options.add_argument("user-data-dir=C:\Users\hadi\AppData\Local\Google\Chrome\User Data") #您的 chrome 配置文件的路徑w = webdriver.Chrome(executable_path="E:Pythonchromedriver.exe", chrome_options=options)w.get("https://www.facebook.com")
在運行此腳本時出現此錯誤:
Traceback(最近一次調用最后一次):<module> 中的文件E:/Python/MoosaBhai/TestoTes.py",第 6 行w = webdriver.Chrome(executable_path="E:\Python\chromedriver.exe", chrome_options=options)__init__ 中的文件C:UsershadiAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriverchromewebdriver.py",第 75 行期望的能力=期望的能力)文件C:UsershadiAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriver
emotewebdriver.py",第 154 行,在 __init__self.start_session(desired_capabilities, browser_profile)文件C:UsershadiAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriver
emotewebdriver.py",第 243 行,在 start_session響應 = self.execute(Command.NEW_SESSION,參數)文件C:UsershadiAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriver
emotewebdriver.py",第 312 行,在執行中self.error_handler.check_response(響應)文件C:UsershadiAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriver
emoteerrorhandler.py",第 242 行,在 check_response引發異常類(消息、屏幕、堆棧跟蹤)selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome 無法啟動:崩潰(驅動程序信息:chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),平臺=Windows NT 10.0.17134 x86_64)
我已經編輯了 chromedriver 的可執行路徑,但是當我運行腳本時,我的 chrome 驅動程序會打開,但之后會卡住 2-3 分鐘,然后因上述以下錯誤而崩潰.
拇指規則
<塊引用>Chrome 在啟動過程中崩潰的一個常見原因是作為 root
用戶(administrator
運行 Chrome>) 在 Linux 上.雖然可以通過在創建 WebDriver 會話時傳遞 --no-sandbox
標志來解決此問題,但這種配置不受支持且不鼓勵使用.您需要將環境配置為以普通用戶身份運行 Chrome.
根據您的代碼試驗,您似乎正在嘗試訪問 Chrome 配置文件,因此您可以使用以下解決方案:
代碼塊:
從 selenium 導入 webdriver從 selenium.webdriver.chrome.options 導入選項選項=選項()options.add_argument("user-data-dir=C:\path\to\your\profile\Google\Chrome\User Data\Profile 2")driver = webdriver.Chrome(executable_path=r'C:path ochromedriver.exe', chrome_options=options)driver.get("https://www.google.co.in")
您可以在此處找到詳細討論 如何通過 Python 打開 Chrome 配置文件
This is my code script:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\Users\hadi\AppData\Local\Google\Chrome\User Data") #Path to your chrome profile
w = webdriver.Chrome(executable_path="E:Pythonchromedriver.exe", chrome_options=options)
w.get("https://www.facebook.com")
and on running this script i'm getting this error:
Traceback (most recent call last):
File "E:/Python/MoosaBhai/TestoTes.py", line 6, in <module>
w = webdriver.Chrome(executable_path="E:\Python\chromedriver.exe", chrome_options=options)
File "C:UsershadiAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriverchromewebdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "C:UsershadiAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriver
emotewebdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:UsershadiAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriver
emotewebdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:UsershadiAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriver
emotewebdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "C:UsershadiAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriver
emoteerrorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 10.0.17134 x86_64)
I've edited my executeable path to chromedriver but when i run the script my chrome driver opens but after that stuck for 2-3minutes and then crashes with the above following error.
Thumb rule
A common cause for Chrome to crash during startup is running Chrome as
root
user (administrator
) on Linux. While it is possible to work around this issue by passing--no-sandbox
flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.
As per your code trials seems you are trying to access a Chrome Profile so you can use the following solution:
Code Block:
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument("user-data-dir=C:\path\to\your\profile\Google\Chrome\User Data\Profile 2") driver = webdriver.Chrome(executable_path=r'C:path ochromedriver.exe', chrome_options=options) driver.get("https://www.google.co.in")
Here you can find a detailed discussion in How to open a Chrome Profile through Python
這篇關于selenium.common.exceptions.WebDriverException:消息:未知錯誤:Chrome 無法啟動:在 Python 中使用 ChromeDriver 和 Selenium 崩潰的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!