【自动化】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')
相关推荐
薛先生_0997 分钟前
js学习语法第一天
开发语言·javascript·学习
报错小能手29 分钟前
深入理解 Linux 虚拟内存管理
开发语言·操作系统
和沐阳学逆向1 小时前
我现在怎么用 CC Switch 管中转站,顺手拿 Codex 举个例子
开发语言·javascript·ecmascript
小仙女的小稀罕1 小时前
听不清重要会议录音急疯?这款常见AI工具听脑AI精准转译
开发语言·人工智能·python
书到用时方恨少!1 小时前
Python random 模块使用指南:从入门到精通
开发语言·python
第一程序员1 小时前
Python 4.0正式发布:新特性与学习建议
python·github
客卿1231 小时前
牛客刷题--找数字-- 字符串检测-字符串 双指针
java·开发语言
IAUTOMOBILE2 小时前
用Python批量处理Excel和CSV文件
jvm·数据库·python
威联通安全存储2 小时前
破除“重前端、轻底层”的数字幻象:如何夯实工业数据的物理底座
前端·python
Amour恋空2 小时前
Java多线程
java·开发语言·python