代码
from selenium import webdriver
import time
driver = webdriver.Edge()
driver.get("http://www.baidu.com")
运行结果
Traceback (most recent call last):
File "D:\Progrom File\python\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "D:\Progrom File\python\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "D:\Progrom File\python\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/Program Files/JetBrains/m230810_w/m0810_w.py", line 3, in <module>
driver = webdriver.Edge()
File "D:\Progrom File\python\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 56, in __init__
self.edge_service.start()
File "D:\Progrom File\python\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'MicrosoftWebDriver.exe' executable needs to be in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687
解决方法
将Edge浏览器驱动msedgedriver.exe 重命名为MicrosoftWebDriver.exe,即可正常运行