Selenium 117.0.5938.150版本用SeleniumWire传代理报错求助
解决SeleniumWire配置代理时
WebDriver.init() got multiple values for argument 'options'报错 这个报错是因为Selenium 4.x版本后,webdriver.Chrome()的参数结构发生了变化:你直接把ChromeDriverManager().install()作为位置参数传入,会被构造函数识别为options参数,导致后续的options=options被重复传递,引发参数冲突。
以下是两种可行的解决方法:
方案一:使用Service类(推荐,符合Selenium 4.x规范)
从Selenium 4.6.0开始,官方推荐通过Service类管理驱动路径,彻底避免参数传递混淆:
from seleniumwire import webdriver from selenium.webdriver.common.by import By from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.service import Service # 导入Service类 user = "fff" password = "fffff" endpoint = "fffff:ffffff" wire_options = { "proxy": { "http": f"http://{user}:{password}@{endpoint}", "https": f"http://{user}:{password}@{endpoint}", } } options = webdriver.ChromeOptions() proxies = wire_options # 用Service指定驱动路径,再传入options和seleniumwire_options driver = webdriver.Chrome( service=Service(ChromeDriverManager().install()), options=options, seleniumwire_options=proxies ) driver.get('https://ff.fff.com/')
方案二:显式指定executable_path关键字参数
如果不想使用Service类,可以通过显式声明executable_path关键字参数,避免位置参数的歧义:
from seleniumwire import webdriver from selenium.webdriver.common.by import By from webdriver_manager.chrome import ChromeDriverManager user = "fff" password = "fffff" endpoint = "fffff:ffffff" wire_options = { "proxy": { "http": f"http://{user}:{password}@{endpoint}", "https": f"http://{user}:{password}@{endpoint}", } } options = webdriver.ChromeOptions() proxies = wire_options # 显式用executable_path指定驱动路径 driver = webdriver.Chrome( executable_path=ChromeDriverManager().install(), options=options, seleniumwire_options=proxies ) driver.get('https://ff.fff.com/')
内容的提问来源于stack exchange,提问作者Prashant Patil
相关产品推荐
相关产品推荐

