Selenium WebDriver 的 Microsoft Edge 驱动程序【附代码】

1、从 Microsoft Edge 驱动程序的官方网站下载与浏览器版本相匹配的驱动程序。

https://msedgewebdriverstorage.z22.web.core.windows.net/https://msedgewebdriverstorage.z22.web.core.windows.net/

2、指向驱动程序(**msedgedriver.exe)**的路径

复制代码
service = Service('./msedgedriver.exe')

3、启动驱动程序

复制代码
browser = webdriver.Edge(service=service, options=options) 

4、关闭浏览器会话

复制代码
browser.quit()

例如:

startBrowser 方法

Python 类中用于初始化和启动 Microsoft Edge 浏览器会话的一个成员函数,这个方法使用了 Selenium WebDriver 来创建和配置浏览器实例

复制代码
     def startBrowser(self):
        service = Service('./msedgedriver.exe')
        options = webdriver.EdgeOptions()  # 创建浏览器选项实例
        options.add_experimental_option('excludeSwitches', ['enable-automation'])
        browser = webdriver.Edge(service=service, options=options)
        # 使用 webdriver.Edge 与 service 和 options 一起创建了一个新的 Edge 浏览器实例

        return browser
相关推荐
郝学胜-神的一滴6 分钟前
深入解析:生成器在UserList中的应用与Python可迭代对象实现原理
开发语言·python·程序人生·算法
李昊哲小课24 分钟前
aiomysql 完整实战教程
python·mysql·pymysql·aiomysql
Csvn34 分钟前
描述符协议与动态属性管理
python
东北甜妹35 分钟前
Ansible
python
JavaWeb学起来42 分钟前
Python学习教程(一)环境安装,基本数据类型,变量
开发语言·python·python基础
迷藏49443 分钟前
# 发散创新:用 Rust实现高性能测试框架的底层逻辑与实战演练
java·开发语言·后端·python·rust
chushiyunen1 小时前
python单例模式、大模型一次加载多次复用
开发语言·python·单例模式
威联通安全存储1 小时前
某大型电力装备制造企业:基于威联通NAS的核心图纸保护与数据治理实践
python
Kang.Charles1 小时前
python读取环境变量
python
Birdy_x1 小时前
Python进阶(1)- logging
python