You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python Selenium启动URL时遇chrome not reachable错误求助

问题描述

我已经查阅过多个类似问题并尝试了所有提出的解决方案,但仍出现相同错误。运行代码后Chrome窗口会打开但URL为空,抛出chrome not reachable异常。

代码示例
options = webdriver.ChromeOptions()
options.add_argument('--disable-infobars')
options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
options.add_argument('--no-sandbox')
options.add_argument('--remote-debugging-port=9222')
options.add_argument('--start-maximized')
options.add_argument('--disable-web-security')
options.add_argument('--disable-webgl')
options.add_argument('--disable-popup-blocking')
#options.add_argument('--headless')
options.add_argument('--disable-setuid-sandbox')
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-extensions')
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument(f"--user-data-dir=C:\Users\user1\AppData\Local\Google\Chrome\User Data\Default")
options.add_argument('--disable-gpu')
#pdb.set_trace()
#service = Service(r'C:\Data\installs\chromedriver.exe')
#service.start()
#print(service.service_url)
#pdb.set_trace()
#driver = webdriver.Remote(service.service_url,options=options)
#driver.implicitly_wait(10)
driver = webdriver.Chrome(service=Service(executable_path=ChromeDriverManager().install()), options=options)
driver.get("https://www.google.com")
print("Chrome Driver Loaded")
异常信息
exception is: Message: chrome not reachable
Stacktrace:
Backtrace:
Ordinal0 [0x0042ACD3+2075859]
Ordinal0 [0x003BEE61+1633889]
Ordinal0 [0x002BB680+571008]
Ordinal0 [0x002B12EA+529130]
补充说明

在Eclipse中通过F9运行代码,Chrome窗口打开但URL为空,无法正常加载目标页面。

环境版本
Google Chrome   107.0.5304.88 (Official Build) (64-bit) (cohort: Stable)
Chromedriver: 107.0.5304.62
解决方案建议
  • 修复用户数据目录路径问题:当前代码用f-string处理路径会导致反斜杠被转义,改用原始字符串格式;同时避免直接使用正在运行的Default用户目录(Chrome已启动时会引发冲突)。修改示例:

    options.add_argument(r"--user-data-dir=C:\Users\user1\AppData\Local\Google\Chrome\User Data\TempProfile")
    

    注:先复制Default目录并重命名为TempProfile,使用该副本作为用户数据目录。

  • 移除冲突的启动参数:--remote-debugging-port=9222会让Chrome进入独立调试模式,与WebDriver的连接逻辑冲突,建议移除。同时暂时去掉--disable-web-security、--disable-blink-features=AutomationControlled等非必要参数,简化配置后测试。

  • 匹配Chrome与ChromeDriver精确版本:当前Chrome版本为107.0.5304.88,ChromeDriver为107.0.5304.62,小版本差异可能导致兼容性问题,下载与Chrome完全一致的ChromeDriver替换现有版本。

  • 清理残留Chrome进程:打开任务管理器,结束所有chrome.exe进程后重新运行代码,避免进程冲突导致无法正常连接。

  • 逐步排查参数问题:先保留最基础配置(仅设置binary_location和窗口最大化参数),确认代码正常运行后,再逐个添加其他参数,定位引发异常的具体参数。

内容的提问来源于stack exchange,提问作者nitin srivastava

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 10:15:32