这段代码有两个问题:

  1. 在使用 ChromeOptions 时,应该使用 add_argument() 方法来添加选项,而不是直接传入参数。

  2. 在创建 webdriver.Chrome 实例时,不支持使用 service 参数来指定 ChromeDriver 的路径和参数。

正确的代码应该是这样的:

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('D:\chromedriver.exe')

driver = webdriver.Chrome(options=chrome_options)

这样就可以正常创建 ChromeDriver 实例了。

Traceback most recent call last File cUsersAdministratorDesktop人工智能2103-2021240192-陈鑫1py line 9 in module options = webdriverChromeOptionsDchromedriverexeTypeError __init__ takes 1 positional argu

原文地址: https://www.cveoy.top/t/topic/g65i 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录