**问题:**我在python中使用pycharm中的selenium编写了一个代码,并使用了几天,直到我遇到这个错误,我在互联网上找到了所有可能的解决方案,但没有运气,所以我被迫编写了我的第一个问题,以获得堆栈溢出中的解决方案。请记住代码工作了几天,然后给予错误。
注意我是python和selenium的初学者我的代码很大,所以我将在运行webdriver之前给出错误和代码设置的部分
from selenium import webdriver
from selenium.webdriver.edge.options import Options
# from selenium.webdriver.common.keys import Key
from time import sleep
from selenium.webdriver.support.select import Select
options = Options()
options = webdriver.EdgeOptions()
options.add_experimental_option("detach", True)
options.add_argument(r"user-data-dir=C:\Users\reals\AppData\Local\Microsoft\Edge\User Data")
options.add_argument("profile-directory=Profile 1")
options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
options.add_extension(r"C:\Users\reals\Downloads\Compressed\ABS-20230126T194006Z-001\ABS.crx")
# create a new Edge driver instance
driver = webdriver.Edge(options=options)
**错误:**在上面的代码中,我们在driver = webdriver.Edge(options=options)
这一行中有错误
完整错误消息
Traceback (most recent call last):
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 195, in _start_process
self.process = subprocess.Popen(
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start
self._start_process(self.path)
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 209, in _start_process
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'msedgedriver' executable needs to be in PATH. Please download from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\reals\PycharmProjects\pythonProject1\jade.py", line 17, in <module>
driver = webdriver.Edge(options=options)
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 73, in __init__
super().__init__(
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 101, in __init__
self.service.start()
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 100, in start
self._start_process(path)
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 195, in _start_process
self.process = subprocess.Popen(
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\reals\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application
响应时间我会尽量在几个小时内尽快响应。感谢大家的帮助
我试着重新安装从python到pycharm的所有东西。我试着使用pythonx32位版本,但没有运气。我试着使用代码之外的所有东西,因为人们解释说这个错误是因为一些东西与你的64和32位系统不匹配,但我还没有尝试任何代码,所以我愿意做任何事情来修复这个错误。
1条答案
按热度按时间o3imoua41#
你好像少了
msedgedriver.exe
您可以将其下载到Microsoft上,然后使用以下命令指定路径:
source