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)
You can use whatever for this tasks. I know that webbrowser module is not able to do it.
You can send the hotkey combination to close the tab (Ctrl + W) using the pykeyboard
library from here, https://github.com/SavinaRoja/PyUserInput.
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)
equal to open shell cmd:
C:\Program Files\Mozilla Firefox\firefox -new-tab http://docs.python.org
also most standard browser include Firefox provided its command line args to open new windows/tab but nothing to close opened tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With