Chrome浏览器

当前位置: 首页 >  Chrome浏览器标签页批量关闭方法

Chrome浏览器标签页批量关闭方法

更新时间:2025-10-12来源:Chrome浏览器官网访问量:

Chrome浏览器标签页批量关闭方法1

要批量关闭Chrome浏览器的标签页,可以使用Python脚本。以下是一个简单的示例:
python
import os
import sys
from selenium import webdriver
替换为你的ChromeDriver路径
chrome_driver_path = 'path/to/your/chromedriver'
打开Chrome浏览器
driver = webdriver.Chrome(chrome_driver_path)
遍历当前目录下的所有文件和文件夹
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith('.') or file.endswith('.htm'):
打开对应的网页
driver.get(os.path.join(root, file))
等待页面加载完成
driver.implicitly_wait(10)
关闭标签页
driver.close()
关闭Chrome浏览器
driver.quit()

请确保将`chrome_driver_path`变量设置为你的ChromeDriver的实际路径。运行此脚本后,它将遍历当前目录下的所有HTML文件和文件夹,并使用Selenium库打开它们,然后关闭对应的标签页。
返回顶部