gpt4 book ai didi

python - 如何在 python 中使用 selenium 中预定义的 chrome 配置文件?

转载 作者:行者123 更新时间:2023-11-30 22:24:09 25 4
gpt4 key购买 nike

我的 Chrome 浏览器中有几个自定义配置文件。例如,我想在我的 selenium 中使用“test 2”配置文件。 (见下图)

/image/iYcG8.png

这是我从互联网上看到的代码。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.add_argument(r'user-data-dir=C:\Users\mycomputer\AppData\Local\Google\Chrome\User Data')
browser = webdriver.Chrome(executable_path=r"C:\Users\mycomputer\AppData\Local\Programs\Python\Python36-32\chromedriver.exe", chrome_options=options)

我如何使用“test 2”配置文件?谢谢。

最佳答案

您只需要再添加一个参数:

options.add_argument('--profile-directory=Profile 1')

配置文件 1 - 是您的配置文件的目录,其名称与配置文件名称不同。您可以浏览 user-data-dir 中的所有配置文件目录。如何找出“test 2”配置文件的目录 - 您可以在这里找到 https://superuser.com/a/723145

关于python - 如何在 python 中使用 selenium 中预定义的 chrome 配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47901696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com