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
相关推荐
巴里巴气1 小时前
selenium基础知识 和 模拟登录selenium版本
爬虫·python·selenium·爬虫模拟登录
19891 小时前
【零基础学AI】第26讲:循环神经网络(RNN)与LSTM - 文本生成
人工智能·python·rnn·神经网络·机器学习·tensorflow·lstm
JavaEdge在掘金1 小时前
Redis 数据倾斜?别慌!从成因到解决方案,一文帮你搞定
python
ansurfen1 小时前
我的第一个AI项目:从零搭建RAG知识库的踩坑之旅
python·llm
前端付豪1 小时前
20、用 Python + API 打造终端天气预报工具(支持城市查询、天气图标、美化输出🧊
后端·python
前端付豪1 小时前
19、用 Python + OpenAI 构建一个命令行 AI 问答助手
后端·python
amazinging2 小时前
北京-4年功能测试2年空窗-报培训班学测开-第四十三天
python·学习
wgyang20163 小时前
我的第一个LangFlow工作流——复读机
python
Zhen (Evan) Wang3 小时前
(豆包)xgb.XGBRegressor 如何进行参数调优
开发语言·python
我爱一条柴ya3 小时前
【AI大模型】线性回归:经典算法的深度解析与实战指南
人工智能·python·算法·ai·ai编程