如何在Chrome中打开机密标签?

问题描述

使用webbrowser模块和webbrowser.open方法,我们可以在新标签页中打开URL。 但是,有什么方法可以使用Python在Google中打开一个秘密标签

import webbrowser

webbrowser.open_new("http://google.com")

解决方法

最好使用os.system()以隐身参数启动chrome。

示例:os.system("C:\path\to\chrome\executable.exe -ArgumentList @( '-incognito','https://www.google.com'")

,

可以使用您用来打开“秘密标签”的方法。试试这个:

webbrowser.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s --incognito")
.open("<URL YOU WANT TO OPEN>")

特殊部分是--incognito。它表示隐身模式(打开秘密/隐身选项卡)。 %s用于表示要打开的URL(由.open函数指定)。旁注:您不能将%s替换为您的URL,否则它将引发webbrowser.Error