这是我的代码:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\Users\shahr\AppData\Local\Google\Chrome\User Data\Profile 1") #Path to your chrome profile
w = webdriver.Chrome(executable_path=r"C:\Program Files (x86)\chromedriver.exe", options=options)
我从其他 StackOverFlow 答案中尝试过此操作,但它拒绝打开所需的配置文件
chrom_options.add_argument("user-data-dir=C:\\Users\robert.car\\AppData\\Local\\Google\\Chrome\\User Data")
chrom_options.add_argument("profile-directory=Profile 1")
user-data-dir 将配置文件视为默认值,您不必指定它。如果有其他内容,请通过配置文件目录参数指定它
创建个人资料的步骤:
open: chrome://地址栏中的版本
![enter image description here](https://i.stack.imgur.com/mRo0r.png)
copy将用户目录文件夹完全复制到例如 c:\tmp\newdir
打开复制的用户数据 (newdir) 并搜索名为 Default 的文件夹。这是配置文件文件夹。
rename默认文件夹为“Profile 1”
现在使用这个:
chrom_options.add_argument("user-data-dir=c:\\tmp\\newdir")
chrom_options.add_argument("profile-directory=Profile 1")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)