当前位置: 首页> 文旅> 艺术 > 应用宝自动下载安装

应用宝自动下载安装

时间:2025/7/9 4:06:19来源:https://blog.csdn.net/qq_43767472/article/details/142106713 浏览次数:0次
import uiautomator2 as u2
from threading import  Thread
import logging
import sys
import os
logger=logging.getLogger("uiautomator2")
logger.setLevel(logging.INFO)
d = u2.connect()"""下载模块"""
class yingyongbao(object):
#初始化屏幕尺寸def __init__(self):self.width, self.height = d.window_size()print(self.width,self.height) #720 1600#os.system("python -m uiautomator2 init")# width=0.15*width# height=0.95*height# print(width,height)  #108.0 1520.0def get_path(self):self.basedir = os.path.dirname(os.path.abspath(__file__))def get_screen_path(self):screen_path = os.path.join(self.basedir,'log')if not os.path.exists(screen_path):os.mkdir(screen_path)return screen_pathdef get_error_result(self):error_path = os.path.join(self.basedir, 'screen')if not os.path.exists(error_path):os.mkdir(error_path)return error_path# def init_device(self):#     os.system("python -m uiautomator2 init")def start_yingyongbao(self):try:os.system("python -m uiautomator2 init")file_path=input("请输入需要下载的文本路径:")with open(file_path, 'r') as f:self.package_list = f.readlines()d.shell("pm grant com.tencent.android.qqdownloader android.permission.'POST_NOTIFICATIONS'")d.app_clear("com.tencent.android.qqdownloader")d.app_start("com.tencent.android.qqdownloader", wait=True)d.sleep(8)try:if "应用宝" == d.xpath('//*[@resource-id="android:id/alertTitle"]').get_text():d.xpath("//*[@resource-id='android:id/button1']").click()except:print("点击应用宝权限后未识别")# if d(textContains="检查是否有更新").exists(timeout=30):#     d.xpath("//*[@resource-id='android:id/button1']").click()if d(textContains="欢迎使用应用宝").exists(timeout=30):d.xpath('//*[@resource-id="com.tencent.android.qqdownloader:id/ri"]').click()if d(textContains="发送通知吗").exists(timeout=30):d.xpath('//*[@resource-id="com.android.permissioncontroller:id/permission_allow_button"]').click()if d(textContains='一键下载').exists(timeout=30):d.press("back")if d(textContains="秒完游戏").exists(timeout=20):d.press("back")except:logger.info("function:" + sys._getframe().f_code.co_name + ":start_yingyongbao:")def login_yingyongbao(self):try:d(resourceId="com.tencent.android.qqdownloader:id/e6", text="我的").click()if d(text="欢迎登录应用宝").exists(timeout=6):d.xpath('//*[@resource-id="com.tencent.android.qqdownloader:id/uy"]').click()d.xpath('//*[@resource-id="com.tencent.android.qqdownloader:id/ac1"]').click()d(text="下载完成后提示安装").right().click()d.press("back")d(text="下载完成后提示安装").wait_gone()except:logger.info("function:" + sys._getframe().f_code.co_name + ":login_yingyongbao:")def down_app(self):#assert_succes=["下载量","评价"]try:for i in range(0, len(self.package_list)):d.shell(f"am start -a android.intent.action.VIEW -d market://details?id={self.package_list[i]} -p com.tencent.android.qqdownloader")#有多个下载apk路径就需要使用如下代码#d.app_wait(self.package_list[i], 60, front=True)# try:#     #首次启动应用宝会选择打开的方法 如果有多个下载途径#     assert d(text="应用宝").exists(2)#     d.xpath("//*[@text='应用宝']").click()#     #d.xpath("//*[@text='仅此一次']").click()#     # d.xpath("//*[@text='始终']").click()#     d.sleep(2)#     d.click(width*0.75, height*0.95)  #540 1520# except:#     pass#try:d(text="下载量").exists(10)d(text="评价").exists(10)# device.xpath('//*[@text="下载"]').click()assert "下载量" in d(text="下载量").get_text() and "评价" in d(text="评价").get_text()# install_num = d(text="下载量").wait(20).exit()d.click(0.15 * self.width, 0.95 * self.height)d.sleep(3)print(f"{self.package_list[i].strip()}已加入到下载名单")except:assert "找不到数据" in d(resourceId="com.tencent.android.qqdownloader:id/v5").get_text()print(f"网络问题导致{self.package_list[i]}下载失败,检查网络")self.package_list_sceen=self.package_list[i].strip()d.screenshot(f'{self.package_list_sceen}.png')# try:#     d(textContains="找不到数据了").exists()#     d(text="重新加载").click()# except:#     print("你的网络断了,检查网络")#     d.screenshot("网络问题.png")continueexcept:logger.info("function:" + sys._getframe().f_code.co_name + ":yinngyongbao_install:")# d(textContains="运营者").click()# element_install_num = d(text="下载量").get_text()# element_evaluate = d(text="评价").get_text()# assert element_install_num=="下载量" and element_evaluate=="评价"# #print(element_install_num,element_evaluate)# d.click(width,height)#断言//*[@text="下载量"] 和 //*[@text="评价"]"""安装模块已写好"""def yingyongbao_install_Permissions(self):d.app_start("com.tencent.android.qqdownloader", wait=True)d.xpath('//*[@text="我的"]').click_exists(timeout=30)#d(resourceId="com.tencent.android.qqdownloader:id/e6",text="我的").click_exists(20)if d(text="欢迎登录应用宝").exists(timeout=6):d.xpath('//*[@resource-id="com.tencent.android.qqdownloader:id/uy"]').click()try:d.xpath("//*[@text='下载安装']").wait(20).click()try:d.xpath("//*[@text='一键安装']").wait(20).click()except Exception as result:print(f"{result}\n没有一键安装按钮,检查是否已经下载了安装包")except:logger.info("function:" + sys._getframe().f_code.co_name + ":yingyongbao_install_Permissions:")try:assert "未知应用" in d(resourceId="android:id/message").get_text()d(resourceId="android:id/button1", text="设置").click()d.xpath('//*[@text="允许来自此来源的应用"]').click()d(text="取消").click()# d(text="安装").click()# d(text="完成").click_exists(timeout=180)d.press("back")d(text="安装未知应用").wait_gone(timeout=5)except:logger.info("function:" + sys._getframe().f_code.co_name + ":yingyongbao_install_Permissions:")# try:
#     d(resourceId="com.tencent.android.qqdownloader:id/gz", text="一键安装").click()
# except Exception as result:
#     print(f"{result}\n没有一键安装按钮,检查是否已经下载了安装包")def yingyongbao_install(self):app_all=[]while True:try:#d.xpath('//*[@resource-id="com.android.packageinstaller:id/install_confirm_question"]').get_text()=="要安装此应用吗?"#assert "安装" in d(text="要安装此应用吗?").get_text()assert "安装" in d(textContains="此应用").get_text()# 检查并点击“要安装此应用吗?”if d(text="要安装此应用吗?").exists(timeout=10):app_name=d.xpath("//*[@resource-id='android:id/alertTitle']").get_text()print(f"安装的应用昵称是{app_name}")app_all.append(app_name)d(text="安装").click()#print(f"正在安装的应用是{self.package_list[i]}")# 等待“正在安装…”出现(注意:这里不调用exists,只是等待)d(text="正在安装…").wait(timeout=10)# 检查并点击“完成”(如果它存在)if d(text="完成").exists(timeout=120):d(text="完成").click()#print(f"安装的应用是{self.package_list[i]}")except:print(f"总共安装了len{app_all}个应用,分别是{app_all}")break# """守护线程要安装的应用"""
# def wait_insatall(self):
#         """会提示安装未知应用"""
#         try:
#             assert "未知应用" in d(resourceId="android:id/message").get_text()
#             d(resourceId="android:id/button1",text="设置").click()
#             d(resourceId="android:id/title", text="允许来自此来源的应用").click()
#         except:
#             pass
#         #d(text="Settings").wait_gone(timeout=1.0) 等待消失
#         d(text="安装").wait(5)
#         d(text="安装",className="android.widget.Button").click()
#         if d(text="已屏蔽不安全的应用").exists(timeout=5):
#             # d(text="知道了").click()
#             d.xpath('//*[@text="更多详情"]').click()
#             d.xpath('//android.widget.ScrollView/android.view.View[3]')  # 需要点击仍要安装
#         d(text="正在安装…").wait(2).exists(timeout=3)
#         d(text="已安装应用。").exists(timeout=5)
#     #会弹出不安全的应用
#         a_thead=Thread(target=self.wait_insatall,args=())
#         b_thead=Thread(target=self.yinngyongbao_install,args=())
#         a_thead.setDaemon(True)
#         a_thead.start()
#         b_thead.start()@staticmethoddef show_menu():print("========================================================== ")print("||    <1>应用宝下载        <2>应用宝安装       <3>    ||\n")print("========================================================== ")if __name__ == '__main__':anzhuang=yingyongbao()"""应用宝下载功能"""while True:anzhuang.show_menu()num = int(input("输入你要选择的功能,用数字替代:先下载后执行安装:"))if num == 1:anzhuang.start_yingyongbao()anzhuang.login_yingyongbao()anzhuang.down_app()print("=======================下载执行完毕=========================== ")elif num == 2:"""应用宝安装功能"""anzhuang.yingyongbao_install_Permissions()anzhuang.yingyongbao_install()else:print("输入有误,重新输入")
关键字:应用宝自动下载安装

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: