我可以从使用以下代码打开的Python关闭上次打开的选项卡(不关闭浏览器)吗?
import webbrowser
webbrowser.get("firefox").open_new_tab(url)
你可以使用任何东西来完成这个任务。我知道webbrowser模块无法做到这一点。
不,您不能以编程方式关闭浏览器(无需破解或创建插件)。
浏览器控制器仅提供打开浏览器的方法,但不提供关闭浏览器的方法。
this 隐式调用 new Process 然后解析命令行参数,例如
import subprocess
subprocess.Popen("firefox -new-tab %s" % url, shell=True)
等于打开shell cmd:
C:\Program Files\Mozilla Firefox\firefox -new-tab http://docs.python.org
大多数标准浏览器也包括 Firefox 提供了它的命令行参数来打开新的窗口/选项卡,但没有关闭打开的选项卡。
You can send the hotkey combination to close the tab (Ctrl + W) using the pykeyboard
library from here, https://github.com/SavinaRoja/PyUserInput.