Selenium Python报错:WebDriver.__init__()收到意外关键字参数executable_path
问题解决:WebDriver.init() 收到意外关键字参数 'executable_path'
错误原因
Selenium 4.x 及以上版本已移除 webdriver.Chrome() 方法中的 executable_path 参数,该功能改由 Service 类实现。
修改后的代码
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service # 配置浏览器选项 option = webdriver.ChromeOptions() # 实例化Service对象,指定驱动文件路径 service = Service('./chromedriver.exe') # 初始化浏览器驱动 driver = webdriver.Chrome(service=service, options=option) driver.get('https://www.google.com/')
简化方案(可选)
若 ChromeDriver 已添加到系统环境变量中,无需手动指定路径,代码可简化为:
from selenium import webdriver from selenium.webdriver.chrome.options import Options option = webdriver.ChromeOptions() driver = webdriver.Chrome(options=option) driver.get('https://www.google.com/')
内容的提问来源于stack exchange,提问作者Huu Quy
相关产品推荐
相关产品推荐

