网友回复
在 Python 中,你可以使用 subprocess 模块调用 Chrome 或 Edge 的命令行参数来以无痕模式打开指定的网址。以下分别给出使用 Chrome 和 Edge 无痕模式打开网址的示例代码。
使用 Chrome 无痕模式打开网址要使用 Chrome 无痕模式打开网址,你可以通过命令行传递 --incognito 参数。以下是示例代码:
import subprocess
def open_url_in_chrome_incognito(url):
try:
# 不同操作系统下 Chrome 的可执行文件路径可能不同
import platform
system = platform.system()
if system == "Windows":
chrome_path = r'"C:\Program Files\Google\Chrome\Application\chrome.exe"'
elif system == "Darwin": # macOS
chrome_path = r'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
elif system == "Linux":
chrome_path = 'google-chrome'
else:
print("不支持的操作系统")
return
...点击查看剩余70%


