Python WebDriver Manager Chrome自定义配置文件

5

我该如何让webdriver_manager.chrome使用自定义的Chrome用户配置文件?

我知道对于selenium webdriver,我可以这样指定:

options = Options()
options.add_argument(f'user-data-dir={script_path}\\User Data\\profile')
driver = webdriver.Chrome(executable_path=f'{script_path}\\chromedriver.exe', options=options)

但是因为我想让chromedriver自己安装正确的版本(因为我要将程序出售给非Python用户),所以我使用了webdriver_manager模块,它看起来像这样:

driver = webdriver.Chrome(ChromeDriverManager().install())

我能否使用webdriver_manager来加载自定义配置文件,以便在网站上登录时保存我的登录数据到我的个人配置文件中?

1个回答

7

您可以使用 webdriver_manager.chrome自定义 Chrome 用户配置文件 来同时运行以下解决方案:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_argument(f'user-data-dir={script_path}\\User Data\\profile')
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=options)
driver.get('https://www.google.com/')

executable_path已被弃用,但是你的另一个答案指明了前进的方向! - ggorlen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接