TypeError: WebDriver.__init__() got multiple values for argument 'executable_path'



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

options = Options()
options.add_argument('--start-maximized')
options.add_extension('D:\小狐狸钱包插件')
ph = 'D:\pythonProject\pythonProject\Scripts'

driver = webdriver.Chrome(executable_path='ph', options=Options)
driver.get('https://gm-portal.changyou.com/Giveaway/index')

#报错信息
Traceback (most recent call last):
  File "D:\pythonProject\gamefish.py", line 93, in <module>
    driver = webdriver.Chrome(executable_path='ph')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: WebDriver.__init__() got multiple values for argument 'executable_path'

为什么报这个错,

你把参数ph的引号去掉试试

【以下回答由 GPT 生成】

问题原因是在创建WebDriver对象时,使用了错误的语法来指定executable_path参数的值。解决方法是将'ph'字符串改为ph变量,并将options参数传递给webdriver.Chrome()构造函数。

以下是修改后的代码:

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

options = Options()
options.add_argument('--start-maximized')
options.add_extension('D:\小狐狸钱包插件')
ph = 'D:\pythonProject\pythonProject\Scripts'

driver = webdriver.Chrome(executable_path=ph, options=options)
driver.get('https://gm-portal.changyou.com/Giveaway/index')

这样修改后应该能够解决问题。如果还有其他问题,请给出具体的错误信息以便进一步分析。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^