ChromeDriver 无法创建默认个人资料目录

2024-10-05 11:06:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python中使用selenium,并尝试使用一些参数来启动chromedriver。

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

def buildDriver():
    options = ChromeOptions()
    options.add_argument('--profile-directory="Default"')
    options.add_argument('--user-data-dir="C:/Temp/ChromeProfile"')
    browser = webdriver.Chrome(chrome_options=options)

driver = buildDriver()

我无法找到解决以下错误的方法:

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot create default profile directory

搜索这个错误不会产生任何有意义的结果,至少对我来说不是。


Tags: fromimportadd参数selenium错误chromeprofile
1条回答
网友
1楼 · 发布于 2024-10-05 11:06:09

原来在添加参数时不能使用引号。

options.add_argument('--profile-directory=Default')
options.add_argument('--user-data-dir=C:/Temp/ChromeProfile')

注意它是--profile-directory=Default,而不是--profile-directory="Default"

这就是我解决问题的原因。

相关问题 更多 >

    热门问题