Python自动关闭浏览器关闭网页的方法

时间:2026-02-15 19:55:38

1、首先,在py官网上下载一个selenium模块,版本根据自己需求定,这里举例为:selenium-2.50.0

Python自动关闭浏览器关闭网页的方法

2、然后,使用离线方式安装selenium模块,因为使用pip在线方式安装,成功率很低。安装方式:打开命令cmd,然后cd 到模块地址 ,然后,install setup.py。

Python自动关闭浏览器关闭网页的方法

3、然后,打开一个空白py,或者编辑一个py文件。

Python自动关闭浏览器关闭网页的方法

4、在py编辑窗口中输入代码:

from selenium.webdriver.chrome.options import Options  

from selenium import webdriver

__browser_url = r'C:\Users\Administrator\AppData\Roaming\360se6\Application\360se.exe'

chrome_options = Options()  

chrome_options.binary_location = __browser_url

driver = webdriver.Chrome(chrome_options=chrome_options)  

driver.get('########')

driver.quit()

可复制,其中######,代表网络地址。C:\Users\Administrator\AppData\Roaming\360se6\Application\360se.exe为浏览器的路径。

.quit()为自动关闭的函数。

Python自动关闭浏览器关闭网页的方法

5、然后,点击run mudle 开始运行该py文件。

Python自动关闭浏览器关闭网页的方法

6、最后,网页被成功打开,并且自动关闭。举例为百度首页。

Python自动关闭浏览器关闭网页的方法

© 2026 长短途
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com