You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium两种启动方式报错求助:WebDriverException与OSError

Selenium Chrome驱动连接问题解决方案

方法1错误修复

你误将**Chrome浏览器主程序(chrome.exe)**当作了ChromeDriver驱动程序,Service类需要指向的是chromedriver.exe,而非Chrome的启动程序。

修复后的代码:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
# 修正路径为chromedriver.exe
service = Service(r"Driver/chromedriver.exe")
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)

同时要确认下载的ChromeDriver版本和你的Chrome浏览器版本(127.0.6533.99)完全匹配,版本号不一致也会导致连接失败。

方法2错误修复

WinError 193一般是驱动程序与系统架构不匹配,或是webdriver-manager下载了错误版本的驱动,可按以下步骤解决:

  1. 强制指定64位驱动下载
    修改代码,明确指定下载64位版本的ChromeDriver:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.os_manager import ChromeType

options = Options()
options.add_argument("start-maximized")
# 强制指定64位架构的驱动
driver = webdriver.Chrome(
    service=Service(ChromeDriverManager(chrome_type=ChromeType.GOOGLE, architecture="64").install()),
    options=options
)
driver.get("https://www.google.com")
  1. 清理webdriver-manager缓存
    找到缓存目录C:\Users\<你的用户名>\.wdm,删除其中所有ChromeDriver相关文件,再重新运行脚本。

  2. 手动下载驱动替代
    如果webdriver-manager仍有问题,直接下载与Chrome版本匹配的64位ChromeDriver,然后参照方法1的方式指定路径使用。

通用排查要点

  • 确认Chrome浏览器和ChromeDriver的主、次版本完全一致
  • 检查杀毒软件是否拦截了chromedriver.exe,必要时添加信任列表
  • 尝试以管理员权限运行Python脚本

内容的提问来源于stack exchange,提问作者Sehal Hasan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 13:47:22