【自动化】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')
相关推荐
许彰午7 小时前
14_Java泛型完全指南
java·windows·python
广州灵眸科技有限公司7 小时前
瑞芯微RV1126B开发板(EASY-EAI-PI2) Easy-Eai编译环境准备与更新
服务器·前端·人工智能·python·深度学习
TechWayfarer8 小时前
IP风险等级评估接入实战:金融信贷如何用IP画像辅助风控审核
python·tcp/ip·安全·金融
Esaka_Forever8 小时前
uv init 完整用法(Python 最快包管理器)
服务器·python·uv
代码中介商10 小时前
C++左值与右值:核心判断法则详解
开发语言·c++
JAVA96510 小时前
JAVA面试-并发篇 05-并发包AQS队列实现原理是什么
java·开发语言·面试
Halo_tjn11 小时前
反射与设计模式1
java·开发语言·算法
神仙别闹11 小时前
基于Python + SQL server 实现(GUI)原神圣遗物管理与角色数值模拟系统
java·数据库·python
珊瑚里的鱼11 小时前
手撕单例模式中的饿汉模式和懒汉模式,懒汉模式还要再多加一个C++11版本的
开发语言·c++·单例模式
是有头发的程序猿11 小时前
电商自动化实战:淘宝/天猫item_get商品详情API全量采集教程(Python源码)
java·python·自动化