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

使用Chrome配置文件启动Selenium失败,报options参数重复赋值错误

解决WebDriver.init() got multiple values for argument 'options'错误

错误原因

Selenium 4及以上版本中,webdriver.Chrome()的参数结构发生了变化,不再支持直接将驱动路径作为第一个位置参数传入。你当前的写法会让PATH被识别为第一个位置参数,而options=options是关键字参数,两者冲突导致报错。另外你的user-data-dir参数里有多余空格,且路径中的反斜杠未正确处理,可能引发额外解析问题。

修复后的代码

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

# 用原始字符串避免反斜杠转义问题,同时去掉user-data-dir后的空格
options = Options()
options.add_argument(r"user-data-dir=C:\Users\omer\AppData\Local\Google\Chrome\User Data\Profile 1")

# 通过Service类传入驱动路径
service = Service("chromedriver.exe")
driver = webdriver.Chrome(service=service, options=options)
driver.get("https://web.whatsapp.com/")

关键修改点

  • 导入Service类管理驱动路径,替代直接传路径的旧写法
  • 路径使用原始字符串(前缀r)避免反斜杠被解析为转义字符
  • 删除user-data-dir和路径之间的空格,保证参数格式正确
  • 实例化webdriver.Chrome时,统一使用关键字参数传递service和options

内容的提问来源于stack exchange,提问作者Ömer Doğan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 02:42:39