我收到此错误! OSError: [WinError 193] %1 不是有效的 Win32 应用程序 :c

问题描述 投票:0回答:1

我今天尝试运行 Python 文件并收到以下错误!有人知道问题出在哪里以及解决方法吗?

(local) C:\Users\user1\Desktop\local>python 1.py
Traceback (most recent call last):
  File "C:\Users\user1\Desktop\local\1.py", line 257, in <module>
    driver = initDriver()
             ^^^^^^^^^^^^
  File "C:\Users\user1\Desktop\local\1.py", line 23, in initDriver
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\Desktop\local\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\Users\user1\Desktop\local\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 50, in __init__
    self.service.start()
  File "C:\Users\user1\Desktop\local\Lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
    self._start_process(self._path)
  File "C:\Users\user1\Desktop\local\Lib\site-packages\selenium\webdriver\common\service.py", line 208, in _start_process
    self.process = subprocess.Popen(
                   ^^^^^^^^^^^^^^^^^
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\user1\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1538, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 193] %1 no es una aplicación Win32 válida

我在 1.py 中有这段代码

import os
import time
import string
import datetime
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

TARGET_URL: str = "www.xd.com"
list1 = ["350","300","320","310","340","330","360","305"]

def initDriver():
    option = webdriver.ChromeOptions()
    option.add_argument("--incognito")
    #option.add_argument("--headless")
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)
    return driver

我尝试更改 webdrivermanager

python selenium-webdriver pip selenium-chromedriver
1个回答
0
投票

您可以在现代 Python / selenium 环境中避免安装机制,如下所示:

from selenium import webdriver
from selenium.webdriver import ChromeOptions

def initDriver():
    options = ChromeOptions()
    options.add_argument("--incognito")
    return webdriver.Chrome(options=options)

平台:

python 3.12.5
selenium 4.23.1
© www.soinside.com 2019 - 2024. All rights reserved.