python - 使用 selenium python 在 Edge 上的用户配置文件
问题描述
每次我使用 selenium 打开边缘时,它都会打开一个新的配置文件。如何设置我自己的个人资料?
解决方案
您可以使用以下代码打开具有特定配置文件的 Edge:
from msedge.selenium_tools import Edge, EdgeOptions
edge_options = EdgeOptions()
edge_options.use_chromium = True
#Here you set the path of the profile ending with User Data not the profile folder
edge_options.add_argument("user-data-dir=C:\\Users\\username\\AppData\\Local\\Microsoft\\Edge\\User Data");
#Here you specify the actual profile folder
edge_options.add_argument("profile-directory=Profile 1");
edge_options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
driver = Edge(options = edge_options, executable_path = "your\\path\\to\\edge\\webdriver\\msedgedriver.exe")
driver.get('https://google.com')
driver.quit()
上面的代码使用MS Edge Selenium 工具。您需要运行以下命令来安装它:
pip install msedge-selenium-tools selenium==3.141
请注意将代码中的所有路径更改为您自己的。如果您不知道特定配置文件的路径,可以检查edge://version/如下所示:
推荐阅读
- javascript - 如何在执行构建之前修改 Node.js 中所需的模块?
- java - Android Glide BlurTransformation
- c - 在 char 数组中存储不同的数据类型
- ios - 呼叫套件识别
- pandas - Pandas Multiindex 计数级别
- android - Android Studio 无法解析 Mockito 类
- c++ - “super”关键字的c ++仿真
- ggplot2 - ggplotly 类似于 python 的函数
- shell - 邮件帐户和松散文件夹使用 AWK 向 CSV 报告。如何从这个例子中实现这一点?
- graph - 空间图(3维图)存在吗?