使用 driver = webdriver.Chrome() 时,遇到以下报错:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.
解决方法:
将下载解压好的chromedriver.exe文件放置在python.exe所在的目录下
1.下载chromedriver.exe文件,版本与chrome版本一致,如果镜像仓库中没有对应的版本,一般秉持向下兼容原则
google镜像:http://chromedriver.storage.googleapis.com/index.html
淘宝镜像:https://npm.taobao.org/mirrors/chromedriver/
2.查看python.exe地址
① win+R 打开运行面板
② 输入cmd命令
③ 在弹出的面板中输入:where python
3.将下载并解压好的chromedriver.exe文件copy到python.exe所在的路径中
PS:如果在第二步中搜索到多个路径,需要copy到pycharm的虚拟环境运行时所启动的python.exe路径下——如果不明白这段话的意思,可以在每个路径下面都copy一份