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

添加Chrome配置文件目录后Selenium Wire代理无法连接的解决咨询

解决Selenium Wire保留Chrome配置文件时的代理连接问题

问题原因

你指定的Chrome配置文件(profile_directory)中可能已保存了代理相关设置,这些设置会覆盖Selenium Wire传入的代理配置,导致代理无法正常工作;另外当前代码的代理配置未包含账号密码,无profile时会触发认证弹窗。

解决方法

方法1:重置目标配置文件的代理设置

  • 手动启动Chrome,加载你的指定配置文件:
    chrome.exe --user-data-dir="path/to/your/user/data/directory" --profile-directory="YourProfileDirectory"
    
  • 打开Chrome设置,搜索“代理”,进入代理设置页面,将代理改为自动检测设置或直接关闭,保存后关闭Chrome。
  • 重新运行代码,配置文件就不会再干扰代理设置。

方法2:代码中强制覆盖代理并添加认证

不想手动改profile的话,给ChromeOptions加参数禁用自带代理,同时在Selenium Wire配置里补上账号密码(避免弹窗):

from seleniumwire import webdriver

proxy_address = "your_proxy_address:your_proxy_port"
proxy_user = "your_proxy_username"
proxy_pass = "your_proxy_password"
user_data_dir = "path/to/your/user/data/directory"
profile_directory = "YourProfileDirectory"

chrome_options = webdriver.ChromeOptions()

# 强制禁用Chrome自带代理设置,避免profile干扰
chrome_options.add_argument('--no-proxy-server')
chrome_options.add_argument('--ignore-certificate-errors')

proxy_options = {
    'proxy': {
        'http': f'http://{proxy_user}:{proxy_pass}@{proxy_address}',
        'https': f'https://{proxy_user}:{proxy_pass}@{proxy_address}',
        'no_proxy': 'localhost,127.0.0.1'
    }
}

chrome_options.add_argument(f'--user-data-dir={user_data_dir}')
chrome_options.add_argument(f'--profile-directory={profile_directory}')

# 新版Selenium用options参数替代chrome_options
driver = webdriver.Chrome(seleniumwire_options=proxy_options, options=chrome_options)

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

方法3:禁用Selenium Wire的自动配置

如果代理有自动配置冲突,在proxy_options里添加auto_config: False强制使用指定代理:

proxy_options = {
    'proxy': {
        'http': f'http://{proxy_user}:{proxy_pass}@{proxy_address}',
        'https': f'https://{proxy_user}:{proxy_pass}@{proxy_address}',
        'no_proxy': 'localhost,127.0.0.1',
        'auto_config': False
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 21:18:31