从 Python 子进程运行 Chrome 不允许使用指定的用户数据目录

问题描述 投票:0回答:1

我正在尝试使用子进程通过 python 脚本打开 chrome,但它不允许我使用指定的用户数据目录,因此默认为我的默认用户数据目录。我收到弹出错误消息“Google chrome 无法读取和写入其数据目录”。

代码:

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

我使用的是 Windows 10。如果我使用 git-bash 命令打开 chrome...

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

...然后就可以正常工作了。我认为这可能是从 python 脚本运行 chrome 时的权限问题,但不确定。

python google-chrome subprocess
1个回答
0
投票

使用exe的完整路径。 (正斜杠应该适用于 Windows)

subprocess.run([
    'C:/Program Files/Google/Chrome/Application/chrome.exe',
    '--remote-debugging-port=9222',
    '--user-data-dir="C:\\selenum\\ChromeProfile"'
])
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.