Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close web browser using python

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?

like image 534
Pissu Pusa Avatar asked Mar 03 '17 01:03

Pissu Pusa


People also ask

How do you close a web page in python?

The close() method is a web driver command which closes the browser window. During the automation process, if there are multiple browser windows opened, then the close() command will close the current browser window that is having attention at that time.

How do I close my browser?

A. The procedure for closing all open Chrome browser tabs has changed over the years, but on most recent Android tablets, press down on the “x” on the end of any open tab. Leave your finger on the tab until the Close All Tabs option appears on screen and then select that option to shut down all of the open pages.

How do you close the current window in python?

Method 3: Using quit() method Or, you can use exit() function after mainloop to exit from the Python program.


Video Answer


2 Answers

For MacOS, you can use below command:

os.system("killall -9 'Google Chrome'")
like image 83
Nishad Hameed Avatar answered Oct 22 '22 23:10

Nishad Hameed


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")
like image 10
Omid Estaji Avatar answered Oct 23 '22 00:10

Omid Estaji