【自动化】Python SeleniumUtil 油猴 工具 自动安装用户脚本

【自动化】Python SeleniumUtil 油猴 工具

【自动化】Python SeleniumUtil 工具-CSDN博客【自动化】Python SeleniumUtil 工具。https://blog.csdn.net/G971005287W/article/details/144565691

油猴工具

复制代码
import time

from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

from 服务.Selenium.SeleniumUtil import SeleniumUtil


class 油猴:
    @staticmethod
    def 新建用户脚本(driver, 用户脚本地址url):
        # 这个地址提前获取一下
        driver.get('chrome-extension://ooicokiaoaoadbpknjehhcdiejmbppod/options.html#nav=utils')

        # 记录所有已知的窗口句柄(包括原始标签页)
        before_handles = SeleniumUtil.标签页.获取所有已知窗口句柄(driver)

        time.sleep(2)
        js = f"""
            document.getElementById('input_dXRpbHNfdXRpbHM_url').value='{用户脚本地址url}'
            document.getElementById('input_dXRpbHNfdXRpbHNfaV91cmw_bu').click()
            return true
        """
        driver.execute_script(js)
        time.sleep(3)

        # 再次记录所有窗口句柄
        after_handles = SeleniumUtil.标签页.获取所有已知窗口句柄(driver)

        SeleniumUtil.标签页.切换到新窗口句柄(driver, before_handles, after_handles)

        # 获取新标签页的 URL
        new_url = driver.current_url
        driver.get(new_url)

        安装按钮元素 = SeleniumUtil.页面元素.get元素ByName属性(driver, "安装", True, 5)
        SeleniumUtil.页面元素.点击元素(安装按钮元素)
        安装按钮元素 = SeleniumUtil.页面元素.get元素ByName属性(driver, "重新安装", True, 3)
        SeleniumUtil.页面元素.点击元素(安装按钮元素)
        print(f"用户脚本安装成功: {new_url}")





if __name__ == '__main__':
    驱动路径 = 'C:\\chromedriver\\129.0.6656.0\\chromedriver.exe'
    debuggerAddress = 'localhost:4973'
    driver = SeleniumUtil.Driver.初始化驱动通过Debug模式(驱动路径, debuggerAddress)
    油猴.新建用户脚本(driver, 'https://www.xxx.com.cn/aa.user.js')
相关推荐
沈浩(种子思维作者)3 小时前
道AI能不能帮助造出黄金?
人工智能·python
曲幽3 小时前
Python新利器:用uv轻松管理venv虚拟环境和pip依赖包
python·pip·uv·init·venv
西猫雷婶3 小时前
卷积运算效果的池化处理|最大值
人工智能·pytorch·python·深度学习·神经网络·机器学习·cnn
前端世界3 小时前
从“看不懂”到“能用”:一次搞清 C 语言指针数组
c语言·开发语言
gao_shengping3 小时前
Queue(队列)两组增删查操作的区别
java·开发语言
weixin_307779133 小时前
Jenkins Pipeline: Multibranch 插件详解:现代CI/CD的多分支管理利器
运维·开发语言·自动化·jenkins·etl
Da Da 泓3 小时前
多线程(四)【线程安全问题】
java·开发语言·jvm·学习·安全·多线程·线程安全问题
桂花饼3 小时前
[首发实测] GPT-5.2 pro 接入指南:SWE-bench 80% 胜率的“工程级”模型,Python 如何实现低成本调用?
python·gpt·ai编程·大模型实战·gemini 3 pro·claude opus 4.5
wuk9983 小时前
C# 开发 FTP 客户端
开发语言·c#
LUU_793 小时前
Day37 深入理解SHAP图
python