selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed with ChromeDriver and Selenium in Python(selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome 无法启动:在 Python 中使用 ChromeDriver 和 Selenium 崩溃) - IT
问题描述
这是我的代码脚本:
从 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 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome 无法启动:在 Python 中使用 ChromeDriver 和 Selenium 崩溃
基础教程推荐
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 筛选NumPy数组 2022-01-01