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

Selenium Chrome WebDriver 配置指定代理不生效问题求助

Selenium Chrome代理不生效解决方案

问题原因

  • 同时使用ChromeOptions传参和Proxy类写入DesiredCapabilities两种代理配置方式,高版本ChromeDriver出现配置冲突,代理规则被覆盖
  • 新版Selenium(4.0+)已废弃chrome_options、desired_capabilities两个传参入口,旧写法传入的配置不会被识别
  • 错误配置了socks代理参数,你的代理为HTTP类型,无需配置socks代理,反而导致类型识别错误
  • 路径未加raw字符串标记,可能存在转义问题导致配置读取异常

正确可运行代码(Selenium4.x通用)

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

# 路径前加r防止反斜杠转义
PATH = r"C:\Program Files (x86)\chromedriver.exe"
PROXY = "212.237.16.60:3128"

chrome_options = webdriver.ChromeOptions()
# 仅需这一行配置代理,加上http协议头避免类型识别错误
chrome_options.add_argument(f'--proxy-server=http://{PROXY}')
# 新版用Service参数指定驱动路径
service = Service(executable_path=PATH)
# 仅传service和options两个参数即可,不需要其他冗余配置
driver = webdriver.Chrome(service=service, options=chrome_options)

driver.get("https://whatismyipaddress.com")

补充排查步骤

  • 执行pip show selenium确认版本,若为3.x版本可将传参改为webdriver.Chrome(PATH, options=chrome_options),无需Service参数
  • 启动浏览器后手动访问chrome://settings/proxy,确认代理配置是否正常传入
  • 若代理需要身份认证,启动参数方式不生效,需通过代理插件方式配置

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.27 01:54:03