python - Chrome 不加载配置文件
问题描述
由于某种原因,程序不加载配置文件。配置文件的位置很好。
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\Aron\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
capabilities = DesiredCapabilities.CHROME.copy()
chromedriver = 'C:\\test\\chromedriver.exe'
# Opening the browser
driver = webdriver.Chrome(executable_path = chromedriver, chrome_options=options, desired_capabilities=capabilities)
解决方案
两步:
1 - 当为配置文件使用空文件夹时,Chrome 会在该文件夹中创建一个新配置文件。如果它创建了配置文件,您可以假设它下次也会加载它。
options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\test\Profile 2")
chromedriver = r'C:\test\chromedriver.exe'
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)
2 - 但要确保您可以使用 chrome://version/ 在 Chrome 中显示使用的配置文件。
options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\test\Profile 2")
chromedriver = r'C:\test\chromedriver.exe'
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)
driver.get('chrome://version/')
input('Enter')
推荐阅读
- java - 使用 Apache POI 将 äöü 写入 Word
- sql - 将 hanadb 特定函数 HIERARCHY 与 R 的 dbplyr 一起使用
- c - 在C中的struct指针中填充数组
- socket.io - 生产中的 Socket.io 返回 400 Bad Request 错误
- django - Django在查询后渲染多对多属性,显示无
- android - Moblie [Android] 上的完整 C++ LibTorch API
- facebook - 从 Graph API 获取 Facebook 广告帐户预付余额
- java - java 与 PHP 在 apache mod_jk 中的同一域上
- python - 功能未获取所有文件夹/文件
- amazon-web-services - Terraform - 多循环或地图