Selenium自动化脚本无法启动Chrome浏览器的问题求助
解决Selenium无法获取Chrome驱动(os error 10054)问题
问题分析
报错核心是Selenium Manager自动下载Chrome驱动时,网络连接被远程主机强制关闭(os error 10054),导致驱动无法获取,最终触发NoSuchDriverException。
解决方案
1. 手动下载并配置ChromeDriver
- 步骤1:确认Chrome版本
打开Chrome浏览器,依次点击右上角「三个点」→「帮助」→「关于Google Chrome」,查看当前Chrome的版本号(如125.0.6422.112)。 - 步骤2:下载匹配的ChromeDriver
下载与Chrome版本完全匹配的ChromeDriver(注意对应Windows系统版本),将下载的chromedriver.exe文件放到以下任意位置:- Python安装目录(例如
C:\Users\CN323\AppData\Local\Programs\Python\Python311) - 你的Python脚本所在目录
- 系统环境变量
PATH包含的目录中
- Python安装目录(例如
- 步骤3:脚本中指定驱动路径(可选)
如果不想依赖环境变量,可在脚本中直接指定ChromeDriver路径,修改后代码如下:from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By import time class demofindelementbyID(): def locate_find_id(self): # 替换为你的chromedriver.exe实际路径 service = Service(executable_path=r"C:\your\path\to\chromedriver.exe") driver = webdriver.Chrome(service=service) driver.get("https://secure.yatra.com/social/common/yatra/signin.htm") driver.maximize_window() driver.find_element(By.ID, 'login-input').send_keys('test@test.com') time.sleep(4) driver.quit() # 执行完操作后关闭驱动 findbyid = demofindelementbyID() findbyid.locate_find_id()
2. 排查网络问题
- 临时关闭防火墙或杀毒软件,测试是否能正常下载驱动
- 如果使用代理网络,确保代理配置正确,能访问ChromeDriver的下载源
- 尝试切换网络环境(如从公司内网切换到家庭网络)测试
3. 更新依赖版本
- 升级Selenium到最新版本:
pip install --upgrade selenium - 将Chrome浏览器更新到最新稳定版,避免版本不匹配导致的驱动下载问题
内容的提问来源于stack exchange,提问作者user15347087
相关产品推荐
相关产品推荐

