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

Selenium WebDriver无法建立新连接问题求助

解决Selenium WebDriver启动时的网络连接错误

从错误日志可以明确:你的代码本身没问题(朋友能正常运行),问题出在ChromeDriverManager自动下载驱动时,无法解析chromedriver.storage.googleapis.com域名,导致无法建立网络连接(对应错误[Errno 11001] getaddrinfo failed)。以下是几种可行的解决方法:

方法1:手动指定ChromeDriver路径(绕开自动下载)

这是最直接的解决方案,跳过自动下载流程:

  1. 查看本地Chrome浏览器版本(设置→关于Chrome),确保和日志中的版本(114.0.5735)一致
  2. 手动下载对应版本的ChromeDriver(匹配你的操作系统),解压得到chromedriver.exe
  3. 修改代码,直接指定驱动的本地路径:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

options = Options()
# 替换为你本地chromedriver.exe的实际路径
driver = webdriver.Chrome(service=Service(r"C:\your\path\to\chromedriver.exe"), options=options)
driver.get("https://www.google.com/")

方法2:修复DNS解析问题

如果ping chromedriver.storage.googleapis.com提示“找不到主机”,说明DNS解析异常:

  • 打开命令提示符执行:ping chromedriver.storage.googleapis.com,验证是否能解析
  • 切换公共DNS服务器:
    1. 打开「控制面板→网络和共享中心→更改适配器设置」
    2. 右键当前网络连接→属性→双击「Internet协议版本4(TCP/IPv4)」
    3. 手动设置DNS为8.8.8.8(谷歌)或114.114.114.114(国内),保存后重试

方法3:检查代理与防火墙设置

  • 若开启了代理,先关闭代理再试;如果必须使用代理,需给Python配置正确的代理参数
  • 检查Windows防火墙是否阻止Python访问网络,将Python程序加入防火墙白名单
  • 公司/校园网络可能屏蔽了目标域名,联系IT部门确认是否允许访问chromedriver.storage.googleapis.com

方法4:使用国内镜像源自动下载

如果仍想保留自动下载功能,可以指定国内镜像源(比如淘宝镜像):

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.driver_cache import DriverCacheManager
from webdriver_manager.core.os_manager import ChromeType

options = Options()
driver = webdriver.Chrome(
    service=Service(
        ChromeDriverManager(
            cache_manager=DriverCacheManager(),
            chrome_type=ChromeType.GOOGLE,
            url="https://npm.taobao.org/mirrors/chromedriver/"
        ).install()
    ),
    options=options
)
driver.get("https://www.google.com/")

内容的提问来源于stack exchange,提问作者Callum Kent

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 20:20:21