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
相关推荐
金融大 k1 小时前
Python 全球指数监控面板:TickDB + REST + WebSocket 完整方案
python·websocket
啊哈哈121381 小时前
系统设计复盘:为什么 Agent 的 ReAct 循环必须内嵌确定性保护层——以 FitMind 健康助手的路由与步骤控制为例
人工智能·python·react
一颗牙牙2 小时前
安装mmcv
开发语言·python·深度学习
大数据魔法师2 小时前
Streamlit(二)- Streamlit 架构与运行机制
python·web
m0_470857642 小时前
PHP怎么实现工厂模式_Factory模式编写指南【指南】
jvm·数据库·python
大数据魔法师3 小时前
Streamlit(三)- Streamlit 多页面应用开发
python·web
我的xiaodoujiao3 小时前
API 接口自动化测试详细图文教程学习系列20--结合Pytest框架使用
python·学习·测试工具·pytest
python在学ing3 小时前
前端-CSS学习笔记
前端·css·python·学习
IT策士4 小时前
Django 从 0 到 1 打造完整电商平台:为什么用 Django 做电商?
后端·python·django
zkkkkkkkkkkkkk4 小时前
Linux进行管理工具Supervisor配置与使用
linux·python·supervisor