这是我的代码:
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 将配置文件视为默认值,您不必指定它。如果是其他内容,请通过配置文件目录参数指定它
创建配置文件的步骤:
打开:地址栏中的 chrome://version
复制用户目录文件夹完全到例如c:\tmp\newdir
打开复制的用户数据 (newdir) 并搜索名为 Default 的文件夹。这是配置文件文件夹。
重命名默认文件夹为“配置文件 1”
现在使用这个:
chrom_options.add_argument("user-data-dir=c:\\tmp\\newdir")
chrom_options.add_argument("profile-directory=Profile 1")
关于python - Chrome 配置文件未加载 Selenium ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65138426/