我想使用 Python 的 webdriver 启动 Chrome 及其默认配置文件,以便 cookie 和站点首选项在会话中保持不变。
我怎样才能做到这一点?
这就是它最终为我工作的原因。
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile
w = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", chrome_options=options)
要查找 chrome 配置文件数据的路径,您需要输入chrome://version/
进入地址栏。对于前。我的显示为C:\Users\pc\AppData\Local\Google\Chrome\User Data\Default
,要在脚本中使用它,我必须排除\Default\
所以我们最终只有C:\Users\pc\AppData\Local\Google\Chrome\User Data
.
另外,如果您想为 selenium 有单独的配置文件:将路径替换为任何其他路径,如果启动时不存在,chrome 将为它创建新的配置文件和目录。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)