如何使用Python关闭Web浏览器

12

我在Python中使用webbrowser.open(url)打开了一个网页浏览器窗口,现在我想关闭使用Python打开的网页浏览器。是否有可能这样做呢?


2
你看到这个了吗:https://dev59.com/HIjca4cB1Zd3GeqP4PWm - Shubham Namdeo
请阅读此内容:https://www.reddit.com/r/learnpython/comments/317yct/i_have_code_that_opens_a_webbrowser_now_how_do_i/ - dima
2个回答

12

没有webbrowser.close方法,你可以使用以下代码来关闭任务(在Windows操作系统中):

首先导入os包:

import os

然后使用系统函数来终止该任务

os.system("taskkill /im firefox.exe /f")
os.system("taskkill /im chrome.exe /f")

1
我们在Chrome隐身窗口中使用什么扩展名? - inquisitiveProgrammer

5

对于MacOS,您可以使用以下命令:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接