使用selenium,但chrome无法启动,需要安装浏览器对应版本(最新)的chromedriver
·
使用selenium,但chrome无法启动,需要安装浏览器对应版本(最新)的chromedriver
一、问题描述
- 使用selenium无法启动chrome,代码
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.baidu.com')
driver.close()
- 报错如下:
D:\python\python.exe D:\pycode\mypycode\case\test06_login.py
Traceback (most recent call last):
File "D:\python\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
creationflags=self.creationflags)
File "D:\python\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "D:\python\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\pycode\mypycode\case\test06_login.py", line 9, in <module>
driver = webdriver.Chrome()
File "D:\python\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
service_log_path, service, keep_alive)
File "D:\python\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 90, in __init__
self.service.start()
File "D:\python\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
二、安装最新版本
-
安装地址
-
查询了浏览器版本:117.0.5927

-
但是国内的镜像网找不到,只更新到114版本
-
需要安装驱动,点击了最下面的网址
https://chromedriver.chromium.org/home -
如图为有效信息
- 点击跳转:https://googlechromelabs.github.io/chrome-for-testing(点击这里直接找到114以后的版本)
-
找到对应版本,点击下载即可

-
解压到python.exe目录下
-


-
配置用户变量


-
重启pycharm
三.测试成功
- 跑一下
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome()
driver.get('http://www.baidu.com')
sleep(3)
driver.close()
- 成功

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐




所有评论(0)