使用Chrome配置文件登录skinport.com时遇WebDriverException错误求助
Chrome配置文件登录Skinport时的DevToolsActivePort错误解决
问题描述
尝试用undetected-chromedriver加载Chrome默认配置文件登录Skinport,代码如下:
import undetected_chromedriver as uc import time option = uc.ChromeOptions() option.add_argument( rf'--user-data-dir=C:\Users\kumpd\AppData\Local\Google\Chrome\User Data') option.add_argument(r'--profile-directory=Default') option.add_argument("--log-level=3") driver = uc.Chrome(options=option) time.sleep(2) driver.get("https://skinport.com") time.sleep(3)
程序打开已登录Google的Chrome后抛出错误:
Traceback (most recent call last): File "C:\Users\kumpd\OneDrive\Desktop\BuffMarket Purchase Bot V3.0\Testing.py", line 18, in <module> driver = uc.Chrome(options=option) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 53, in __new__ instance.__init__(*args, **kwargs) File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__ super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog", File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__ RemoteWebDriver.__init__( File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 266, in __init__ self.start_session(capabilities, browser_profile) File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 357, in start_session response = self.execute(Command.NEW_SESSION, parameters) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute self.error_handler.check_response(response) File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, 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: GetHandleVerifier [0x0087DCE3+50899] (No symbol) [0x0080E111] (No symbol) [0x00715588] (No symbol) [0x0073281C] (No symbol) [0x0072F479] (No symbol) [0x00761FFE] (No symbol) [0x00761CEC] (No symbol) [0x0075B6F6] (No symbol) [0x00737708] (No symbol) [0x0073886D] GetHandleVerifier [0x00AE3EAE+2566302] GetHandleVerifier [0x00B192B1+2784417] GetHandleVerifier [0x00B1327C+2759788] GetHandleVerifier [0x00915740+672048] (No symbol) [0x00818872] (No symbol) [0x008141C8] (No symbol) [0x008142AB] (No symbol) [0x008071B7] BaseThreadInitThunk [0x76D97D49+25] RtlInitializeExceptionChain [0x77B6B74B+107] RtlClearBits [0x77B6B6CF+191]
同时,打开的网页未处于登录状态。
*更新:使用普通selenium webdriver的代码可手动导航至网页并保持登录状态,但原undetected-chromedriver的错误仍存在,导致后续程序无法运行:
from selenium import webdriver from selenium.webdriver.chrome.options import Options exec_path_driver = r"C:\chromedriver_win32\chromedriver.exe" ch_options = Options() ch_options.add_argument("user-data-dir=C:\\Users\\kumpd\\\AppData\\Local\\Google\\Chrome\\User Data") driver = webdriver.Chrome(executable_path=exec_path_driver, options=ch_options) driver.get("https://skinport.com")
错误原因
- Chrome进程冲突:指定的
User Data目录对应的Chrome实例已在后台运行,undetected-chromedriver无法获取调试端口,导致启动失败。 - undetected-chromedriver特性冲突:该库会修改Chrome启动参数以绕过反爬检测,直接复用默认用户目录时,可能和现有Chrome会话的调试端口、配置文件锁定机制冲突。
- 权限或端口问题:程序无权限访问DevTools端口文件,或端口被其他进程占用。
解决方案
1. 清理后台Chrome进程
打开任务管理器,结束所有chrome.exe进程(包括后台隐藏进程),再重新运行undetected-chromedriver代码。
2. 使用专用Chrome配置目录
复制默认User Data目录到新路径(如D:\ChromeBotProfile),避免和日常使用的Chrome实例冲突:
import undetected_chromedriver as uc import time option = uc.ChromeOptions() # 使用复制后的专用配置目录 option.add_argument(r'--user-data-dir=D:\ChromeBotProfile') option.add_argument(r'--profile-directory=Default') option.add_argument("--log-level=3") # 添加参数避免权限和端口问题 option.add_argument("--no-sandbox") option.add_argument("--disable-dev-shm-usage") option.add_argument("--remote-debugging-port=9222") driver = uc.Chrome(options=option) time.sleep(2) driver.get("https://skinport.com") time.sleep(3)
注意:先手动打开Chrome,指定该新配置目录并登录Skinport,保存登录状态后再运行代码。
3. 更新并适配undetected-chromedriver
- 更新到最新版本,修复版本兼容问题:
pip install --upgrade undetected-chromedriver
- 指定Chrome二进制文件路径,确保版本匹配:
option.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
4. 优化普通webdriver配置(若切换回普通版本)
如果选择使用普通selenium webdriver,添加参数解决潜在错误:
from selenium import webdriver from selenium.webdriver.chrome.options import Options exec_path_driver = r"C:\chromedriver_win32\chromedriver.exe" ch_options = Options() ch_options.add_argument("user-data-dir=C:\\Users\\kumpd\\AppData\\Local\\Google\\Chrome\\User Data") ch_options.add_argument("--no-sandbox") ch_options.add_argument("--disable-dev-shm-usage") ch_options.add_argument("--remote-debugging-port=9222") driver = webdriver.Chrome(executable_path=exec_path_driver, options=ch_options) driver.get("https://skinport.com")
登录状态未保留的解决要点
- 确保使用的配置目录已手动登录Skinport,且Chrome已开启「自动登录」和「保存密码」功能。
- 代码运行期间,不要手动操作同一配置目录的Chrome实例,避免会话数据被覆盖。
内容的提问来源于stack exchange,提问作者Dallin Kump
相关产品推荐
相关产品推荐

