[英]How to load default profile in Chrome using Python Selenium Webdriver?
[英]How to load custom profile in Chrome using Python Selenium Webdriver?
我尝试使用 python selenium webdriver 在 chrome 中启动自定义配置文件。 但是我在运行时遇到了错误。 我尝试了参数 --no-sandbox、--disable-dev-shm-usage、--remote-debugging-port=xxxx。 但没有工作。
这是代码。
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import time
options = webdriver.ChromeOptions()
options.add_argument("--profile-directory=Profile 6")
options.add_argument("--user-data-dir=C:/Users/SIM/AppData/Local/Google/Chrome/User Data")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
time.sleep(3)
这是输出。
D:\me\web\fbot\src>python script_.py
Opening in existing browser session.
[7488:16428:1223/013230.522:ERROR:broker_win.cc(56)] Error reading broker pipe: The pipe has been ended. (0x6D)
Traceback (most recent call last):
File "D:\me\web\fbot\src\script_.py", line 10, in <module>
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
File "C:\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
super().__init__(
File "C:\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 106, in __init__
super().__init__(
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 288, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 381, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
Backtrace:
(No symbol) [0x0103F243]
(No symbol) [0x00FC7FD1]
(No symbol) [0x00EBD04D]
(No symbol) [0x00EDC24E]
(No symbol) [0x00ED82E9]
(No symbol) [0x00F0F056]
(No symbol) [0x00F0EB2A]
(No symbol) [0x00F08386]
(No symbol) [0x00EE163C]
(No symbol) [0x00EE269D]
GetHandleVerifier [0x012D9A22+2655074]
GetHandleVerifier [0x012CCA24+2601828]
GetHandleVerifier [0x010E8C0A+619850]
GetHandleVerifier [0x010E7830+614768]
(No symbol) [0x00FD05FC]
(No symbol) [0x00FD5968]
(No symbol) [0x00FD5A55]
(No symbol) [0x00FE051B]
BaseThreadInitThunk [0x7762FA29+25]
RtlGetAppContainerNamedObjectPath [0x77CD7A7E+286]
RtlGetAppContainerNamedObjectPath [0x77CD7A4E+238]
请帮我解决这个错误。
我假设你的配置文件路径是错误的,尝试将此命令添加到你的驱动程序类:
options.add_argument("user-data-dir=/Users/alexiseggermont/Library/Application Support/Google/Chrome/Default/")
此路径可用于 Mac 或 Linux 操作系统。 另外,将“默认”重命名为您的个人资料 ID(对我来说,在大多数情况下,它是“个人资料 1”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.