python selenium Edge

很多时候需要通过webdriver获取我们所需要的东西

升级win自带浏览器至edge

找到edge版本:

 

进入:WebDriver-Microsoft 

下载对应版本:

 

 

将下载后的文件解压,将解压后的msedgedriver.exe文件复制到python环境目录Scripts中

python 调用代码如下:

# -*- coding:utf-8 -*-
import time

from selenium import webdriver

driver = webdriver.Edge()

driver.get('https://www.baidu.com')
# 做延迟为了观看效果
time.sleep(30)

driver.close()
driver.quit()

此时运行报错:

Traceback (most recent call last):
  File "D:/Program Files/wk/scf/main.py", line 6, in <module>
    driver = webdriver.Edge()
  File "D:\Program Files\wk\scf\venv\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 56, in __init__
    self.edge_service.start()
  File "D:\Program Files\wk\scf\venv\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'MicrosoftWebDriver.exe' executable needs to be in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687

 

查看 Edge源码

class WebDriver(RemoteWebDriver):

    def __init__(self, executable_path='MicrosoftWebDriver.exe',
                 capabilities=None, port=0, verbose=False, service_log_path=None,
                 log_path=None, keep_alive=False):
executable_path=MicrosoftWebDriver.exe

需要将msedgedriver.exe重命名为MicrosoftWebDriver.exe
再次运行程序:

 

posted @ 2020-08-15 16:39  烟雨半生  阅读(3924)  评论(0编辑  收藏  举报