selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH.
原因
出现此错误的原因是未安装相应的浏览器驱动
解决办法
1、安装 webdriver
各大浏览器驱动下载地址https://docs.seleniumhq.org/download/
Firefox:https://github.com/mozilla/geckodriver/releases/
Chrome:https://sites.google.com/a/chromium.org/chromedriver/
IE:http://selenium-release.storage.googleapis.com/index.html
2、解压、添加路径
下载解压后将对用的驱动复制到你浏览器的安装目录下,
如(C:\Program Files\Mozilla Firefox);
然后在环境变量Path中添加路径:C:\Program Files\Mozilla Firefox
再次运行即可。
或者:每次在启动浏览器时增加executable_path=
参数即可,如:
from selenium import webdriver
path = 'C://chromedriver'
browser = webdriver.Chrome(executable_path=path)
browser.get('https://www.baidu.com')
此处的path指你下载的浏览器驱动对应的绝对路径
来源:CSDN
作者:JaysonWong
链接:https://blog.csdn.net/JaysonWong/article/details/103989095