Python Selenium启动浏览器报错[WinError193]:%1不是有效Win32应用
问题描述
开发Python Selenium代码时,启动浏览器遭遇错误[WinError 193] %1 is not a valid Win32 application,经调试确认该问题与Selenium WebDriver相关。
报错堆栈信息如下:
Traceback (most recent call last): File "path/to/navegador.py", line 49, in iniciar_navegador navegador = webdriver.Chrome(service=servico, options=chrome_options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "path/to/selenium/webdriver/chrome/webdriver.py", line 45, in __init__ super().__init__( File "path/to/selenium/webdriver/chromium/webdriver.py", line 55, in __init__ self.service.start() File "path/to/selenium/webdriver/common/service.py", line 98, in start self._start_process(self._path) File "path/to/selenium/webdriver/common/service.py", line 208, in _start_process self.process = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "path/to/python/Lib/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "path/to/python/Lib/subprocess.py", line 1538, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
解决方案
解决该问题的关键是明确错误成因,首先通过以下代码检查ChromeDriver的安装路径:
driver_path = ChromeDriverManager().install() print(f"ChromeDriver path: {driver_path}")
打印结果显示,程序获取的并非chromedriver.exe,而是其他类型文件:
ChromeDriver path: C:\Users\User\.wdm\drivers\chromedriver\win64\127.0.6533.72\chromedriver-win32/THIRD_PARTY_NOTICES.chromedriver
解决步骤:
- 打开文件资源管理器,进入上述打印的安装目录
- 删除目录中的
LICENSE.chromedriver和THIRD_PARTY_NOTICES.chromedriver两个文件,仅保留chromedriver.exe - 重新运行代码,浏览器即可正常启动,代码恢复正常运行
内容的提问来源于stack exchange,提问作者forest VQV
相关产品推荐
相关产品推荐

