当前位置: 首页 > news >正文

【波点音乐看广告】

import uiautomator2 as u2
import time
from datetime import datetime
import xml.etree.ElementTree as ET
import re
import os

连接设备

d = u2.connect()
os.system(‘adb shell chmod 775 /data/local/tmp/atx-agent’)
os.system(‘adb shell /data/local/tmp/atx-agent server -d’)

打印设备信息

print(d.info)
def print_description_to_file(d):
# 获取当前页面的 XML结构
xml_content = d.dump_hierarchy()

# 解析 XML结构
root = ET.fromstring(xml_content)# 定义正则表达式
time_pattern = re.compile(r'\d{2}:\d{2}:\d{2}')with open('test.txt', 'a') as f:# 遍历所有元素for element in root.iter():# 检查元素是否可点击if element.attrib.get('clickable', 'false').lower() == 'true':# 获取 description 属性值description = element.attrib.get('content-desc', '')# 使用正则表达式匹配if time_pattern.match(description):# 写入文件print("Description 属性值:", description)f.write("Description 属性值: " + description + '\n')

def swipe_left_to_right(d):
width, height = d.window_size()
start_x = width // 4
start_y = height // 2
end_x = width * 3 // 4
end_y = height // 2
d.swipe(start_x, start_y, end_x, end_y)
def screenshot_png():
now = datetime.now().strftime(“%Y_%m_%d_%H%M_%S”)
d.screenshot(f’{now}.png’)

d.app_uninstall(“cn.wenyu.bodian”)

d.app_install(“cn.wenyu.bodian.apk”)

d.app_clear(“cn.wenyu.bodian”)

num=1

while True:
# 启动应用
try:
d.app_start(“cn.wenyu.bodian”, stop=True,wait=True)
print(“应用启动成功”)
except Exception as e:
print(“应用启动失败:”, e)
exit(1)
try:
# d(text=“允许”).click()
# d.xpath(‘//*[@resource-id=“android:id/content”]/android.widget.FrameLayout[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.widget.ImageView[2]’).click()
# print(“点击同意:pass”)
# d(description=‘微信登录领VIP’).click()
# print(“点击微信登录领VIP:pass”)
# # 点击同意并继续
# d(description=‘同意并继续’).click()
# print(“点击微同意并继续:pass”)
pass
except Exception as e:
print(“账号已登录元素不存在:”, e)

if d(text='跳过广告').exists:d(text='跳过广告').click()print("点击:跳过广告")time.sleep(2)
else:pass
if d(description='去看看').exists:d.click(0.49, 0.324)print("点击:非去看看")time.sleep(2)
else:pass
#  # 登录后点击我的
print_description_to_file(d)
time.sleep(2)
d.click(0.681, 0.074)
# d.xpath('//*[@resource-id="android:id/content"]/android.widget.FrameLayout[1]/android.view.View[1]/android.view.View[1]/android.view.View[1]/android.widget.ImageView[5]').click_exists()
# time.sleep(6)
print("点击了我的图标")
# 开始看广告了
if d(description='开启免费模式').exists:d(description='开启免费模式').click()print('执行:d(description=开启免费模式).click()')
else:d.click(0.574, 0.078)print('开始看广告了d.click(0.574, 0.078)')
# 点击获取更多时间
d(description='获取更多时间').click_exists()
# 计时器
start_time=time.time()
if d(description='关闭声音').exists:while d(description='关闭声音').exists:elapsed_time = time.time() - start_timetime.sleep(elapsed_time)  # 可以根据实际情况调整等待间隔print('等待',elapsed_time,'秒')try:d(description='关闭广告').click_exists()print('看的广告1')except  Exception as e:print("此元素不存在:", e)
else:try:d(text='点击一下,立即免费听歌').wait(timeout=4)  # 等待 4 秒time.sleep(3)d(text='点击一下,立即免费听歌').click()print('点击一下,立即免费听歌')time.sleep(3)d.keyevent('4')time.sleep(2)d(resourceId='cn.wenyu.bodian:id/tme_ad_skip_button').click()print('看的广告2')except  Exception as e:print("此元素不存在:", e)
print("马上执行忘了")
time.sleep(3)
num=num+1
print('执行第:',num,'次看广告')
http://www.lryc.cn/news/354306.html

相关文章:

  • [SWPUCTF 2021 新生赛]pop
  • 【DevOps】Jenkins + Dockerfile自动部署Maven(SpringBoot)项目
  • 【C++】——入门基础知识超详解
  • ChatGPT技术演进简介
  • C语言 | Leetcode C语言题解之第114题二叉树展开为链表
  • Vue 子组件向父组件传值
  • 【前端笔记】Vue项目报错Error: Cannot find module ‘webpack/lib/RuleSet‘
  • edge浏览器的网页复制
  • 视频播放器-Kodi
  • Helm安装kafka3.7.0无持久化(KRaft 模式集群)
  • 【机器学习】期望最大化(EM)算法
  • 【Python】机器学习中的过采样和欠采样:处理不平衡数据集的关键技术
  • 重新思考:Netflix 的边缘负载均衡
  • 元组的创建和删除
  • CSS3用户界面
  • STL源码刨析:序列式容器之vector
  • Flutter 中的 AbsorbPointer 小部件:全面指南
  • Web开发学习总结
  • springboot相关知识集锦----1
  • App推广新境界:Xinstall助你轻松突破运营痛点,实现用户快速增长!
  • YOLOv10 论文学习
  • [Spring Boot]baomidou 多数据源
  • Drone+Gitee自动执行构建、测试和发布工作流
  • Unity3D MMORPG 主城角色动画控制与消息触发详解
  • 【Text2SQL 经典模型】HydraNet
  • Mysql-根据字段名查询字段在哪些表里
  • 牛逼!50.3K Star!一个自动将屏幕截图转换为代码的开源工具
  • 八种单例模式
  • 禅道密码正确但是登录异常处理
  • Go微服务: Nacos的搭建和基础API的使用