
1. 安装`selenium`库(如果已经安装):
bash
pip install selenium
2. 编写Python脚本:
python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import os
设置Chrome浏览器路径
chrome_path = "C:\\Program Files (x86)\\Google\\Chrome\\Application\chrome.exe"
设置Chrome浏览器驱动路径
chrome_driver_path = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe"
设置Chrome浏览器启动参数
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
创建Chrome浏览器实例
driver = webdriver.Chrome(executable_path=chrome_path, options=chrome_options)
定义启用插件的函数
def enable_plugin(plugin_name):
driver.execute_script(f"document.querySelector('{plugin_name}').disabled = false;")
定义停用插件的函数
def disable_plugin(plugin_name):
driver.execute_script(f"document.querySelector('{plugin_name}').disabled = true;")
批量启用插件
for plugin_name in ["插件1", "插件2", "插件3"]:
enable_plugin(plugin_name)
关闭Chrome浏览器
driver.quit()
将上述代码保存为一个`.py`文件,例如`enable_disable_plugins.py`,然后在命令行中运行:
bash
python enable_disable_plugins.py
这将根据插件名称启用或停用相应的插件。



