【自动化】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')
相关推荐
冷雨夜中漫步4 小时前
Python快速入门(6)——for/if/while语句
开发语言·经验分享·笔记·python
郝学胜-神的一滴5 小时前
深入解析Python字典的继承关系:从abc模块看设计之美
网络·数据结构·python·程序人生
百锦再5 小时前
Reactive编程入门:Project Reactor 深度指南
前端·javascript·python·react.js·django·前端框架·reactjs
m0_736919106 小时前
C++代码风格检查工具
开发语言·c++·算法
喵手7 小时前
Python爬虫实战:旅游数据采集实战 - 携程&去哪儿酒店机票价格监控完整方案(附CSV导出 + SQLite持久化存储)!
爬虫·python·爬虫实战·零基础python爬虫教学·采集结果csv导出·旅游数据采集·携程/去哪儿酒店机票价格监控
2501_944934737 小时前
高职大数据技术专业,CDA和Python认证优先考哪个?
大数据·开发语言·python
helloworldandy7 小时前
使用Pandas进行数据分析:从数据清洗到可视化
jvm·数据库·python
黎雁·泠崖7 小时前
【魔法森林冒险】5/14 Allen类(三):任务进度与状态管理
java·开发语言
2301_763472468 小时前
C++20概念(Concepts)入门指南
开发语言·c++·算法
肖永威8 小时前
macOS环境安装/卸载python实践笔记
笔记·python·macos