How to close web browser using python

瘦欲@ 提交于 2020-12-28 07:48:40

问题


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?


回答1:


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")



回答2:


For MacOS, you can use below command:

os.system("killall -9 'Google Chrome'")


来源:https://stackoverflow.com/questions/42568922/how-to-close-web-browser-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!