关闭上次打开的标签页 [英] Close last opened tab
问题描述
我可以关闭使用以下代码打开的 Python 中最近打开的选项卡(不关闭浏览器)吗?
Can I close last opened tab (without closing the browser) from Python that was opened with the following code?
import webbrowser
webbrowser.get("firefox").open_new_tab(url)
您可以为该任务使用任何东西。我知道 webbrowser 模块无法执行此操作。
You can use whatever for this tasks. I know that webbrowser module is not able to do it.
推荐答案
不,您不能以编程方式关闭浏览器(无需黑客或创建插件)。
No, you can't close browser programmatically(without hacking or create plug-in).
浏览器控制器仅提供打开浏览器的方法,而不提供关闭方法。
the browser controller only provide methods to open browser but not to close.
这会隐式调用新流程,然后解析命令行参数,例如
this implicitly call new Process then parse command-line arguments such as
import subprocess
subprocess.Popen("firefox -new-tab %s" % url, shell=True)
等于打开shell cmd:
equal to open shell cmd:
C:\Program Files\Mozilla Firefox\firefox -new -tab
http://docs.python.org
大多数标准浏览器也包括Firefox,但其命令行参数打开新窗口/标签页,但无法关闭打开的标签页。
also most standard browser include Firefox provided its command line args to open new windows/tab but nothing to close opened tab.
这篇关于关闭上次打开的标签页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!