尝试使用Python在Selenium上使用默认用户打开chrome

zfycwa2u  于 2023-02-27  发布在  Go
关注(0)|答案(1)|浏览(148)

我在另一篇文章中看到了这种实现选项的方法..但它仍然不工作.

尝试打开默认用户配置文件,而不是未登录的chrome选项卡。

k5hmc34c

k5hmc34c1#

这不是正确的方法,你必须添加两个参数:user-data-dirprofile-directory。此外,最好使用service而不是executable_path,因为它已被弃用。

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\pc1\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument("profile-directory=Profile 1")

chromedriver_path = '...'
driver = webdriver.Chrome(service=Service(chromedriver_path), options=options)

相关问题