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

Selenium脚本运行报错[WinError 193]:无效Win32应用程序求助

修复WinError 193的解决方案

这个错误是因为ChromeDriver与系统、Python或Chrome的位数不匹配,或者驱动文件损坏导致的,以下是具体修复步骤:

1. 确认Python与Chrome的位数一致性

  • 打开命令提示符,执行以下命令检查Python位数:
    python -c "import sys; print(sys.maxsize > 2**32)"
    
    • 输出True表示Python是64位,False是32位。
  • 你的Chrome是64位,需确保Python和ChromeDriver也为64位,三者位数统一。

2. 强制指定ChromeDriver位数安装

修改脚本中驱动安装的代码,强制下载64位ChromeDriver:

#!/usr/bin/env python3
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
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
import time
  
# Configure Chrome options (optional)
options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")  # Open browser maximized
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0")
options.add_argument("--headless")  # Run in background (no GUI)
options.add_experimental_option("detach", True)
  
# 强制下载64位ChromeDriver
driver_path = ChromeDriverManager(chrome_type=ChromeType.GOOGLE, platform="win64").install()
drv = webdriver.Chrome(service=Service(driver_path), options=options)

3. 手动下载匹配版本的ChromeDriver

  • 找到与Chrome 141.0.7390.54版本完全对应的ChromeDriver,下载64位版本。
  • 在脚本中手动指定驱动路径:
    service = Service(executable_path="C:\\你的ChromeDriver路径\\chromedriver.exe")
    drv = webdriver.Chrome(service=service, options=options)
    

4. 清理webdriver-manager缓存

  • 前往路径C:\Users\<你的用户名>\.wdm\drivers\chromedriver,删除所有缓存的驱动文件。
  • 重新运行脚本,让webdriver-manager重新下载完整的驱动。

5. 指定Chrome二进制文件路径(可选)

如果Chrome未安装在默认路径,需在options中指定:

options.binary_location = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 06:43:11