python - Python Selenium Chrome 扩展设置未使用 .crx 文件加载
问题描述
我正在使用 Selenium 开发 Python。
我想出了如何使用扩展程序运行 Chrome,唯一的缺点是扩展程序具有设置,并且在启动自动 Chrome 会话时这些设置始终为空白。
运行 crx 文件时在哪里或如何保存设置?我尝试查看扩展文件夹中的所有文件,但我没有在其中找到我的当前设置。它们可能存储在配置文件中吗?
在我用来打开带有扩展名的 chrome 驱动程序的代码下方。
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
executable_path = "/webdrivers"
os.environ["webdriver.chrome.driver"] = executable_path
chrome_options = Options()
chrome_options.add_extension('/webdrivers/extension_3_1_0_0.crx')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("http://stackoverflow.com")
我不想在每次开始会话时都配置这些设置。我怎样才能让这些设置保持不变?
提前致谢!
解决方案
我已经通过使用 chrome 驱动程序加载配置文件自己修复了它。
options = Options()
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=DIRECTORYTOPROFILEFOLDERWITHINAPPDATA")
结案。
推荐阅读
- sql - Google Big Query 中的数据透视表
- auth0 - Auth0 使用通用登录的静默身份验证
- mysql - 如何从 MySQL 中与服务器不同时区的日期字段中选择 unix 时间戳?
- java - 尝试使用 web3j 部署以太坊智能合约时出错
- javascript - 无法读取未定义的属性“nativeElement”(Ionic 3 和 Angular 5)
- c++ - C++11 右值引用寻址
- ruby - Ruby:如何从 ruby 每种方法返回单值
- javascript - 如何使用数据库通过 api.ai 提出问题
- r - 在没有两个完整周期数据的情况下检测季节性
- hyperledger-fabric - Hyperledger-Composer:ping 网络管理卡时“访问被拒绝”