How to close web browser using python

Question:

I have opened a webbrowser window using webbrowser.open(url) in python now I want to close the webbrowser opened using python. Is it possible to do so?

Asked By: Pissu Pusa

||

Answers:

There is no webbrowser.close, you can use these codes to close the task(in Windows OS):

First Import os package with

import os

then use system function to kill the task

os.system("taskkill /im firefox.exe /f")
os.system("taskkill /im chrome.exe /f")
Answered By: Omid Estaji

For MacOS, you can use below command:

os.system("killall -9 'Google Chrome'")
Answered By: Nishad Hameed
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.