使用 driver = webdriver.Chrome() 时,遇到以下报错:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.
两种解决方法:
(1)在webdriver.Chrome()中添加executable_path参数,参数value = chromedriver.exe文件所在路径,示例:
from selenium import webdriver
chrome_driver_path = "D:\Chrome\chromedriver\chromedriver.exe"
driver = webdriver.Chrome(executable_path=chrome_driver_path)
driver.get("http://baidu.com")
(2)修改webdriver.Chrome()源码中的默认执行路径,将DEFAULT_EXECUTEABLE_PATH修改为本地chromedriver.exe文件所在路径,示例: