从Python子进程运行Chrome将不允许使用指定的UserDataDir

2024-04-24 04:43:56 发布

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

我试图通过使用子流程的python脚本打开chrome,但它不允许我使用指定的用户数据目录,因此默认为默认的用户数据目录。我得到一个弹出错误,读“谷歌浏览器无法读写其数据目录”

代码:

if __name__ == '__main__':
    subprocess.run([
        'chrome.exe',
        '--remote-debugging-port=9222',
        '--user-data-dir="C:\\selenum\\ChromeProfile"'
        ])

我正在使用Windows10。如果我用git bash命令打开chrome

chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\selenum\ChromeProfile"

…那么它就可以正常工作了。我认为在用python脚本运行chrome时,这可能是一个权限问题,但不确定


Tags: 数据用户目录脚本dataremoteportdir