python使用adb驱动手机自动完成“闲鱼”每日浏览得红包

本文介绍了一种使用ADB命令自动化操作安卓手机上的闲鱼APP的方法,包括呼醒屏幕、解锁、打开APP及执行特定操作的详细步骤。通过Python脚本实现对手机的控制,适用于不同的手机型号。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

初次是基于像素得,因为手机不同需要修改。

import time
import os


# 获取APP名称
def get_app_name():
    app_name = os.popen('adb shell dumpsys window w |findstr \/ |findstr name=')
    print(app_name)


# 呼醒屏幕
def wake_up():
    # 获取电源状态
    power_state = os.popen(
        "adb shell dumpsys power | findstr \"Display Power: state=\"").read().strip('\n')
    if power_state.split('=')[-1] == 'OFF':
        print("唤醒屏幕")
        os.system('adb shell input keyevent 26')
    else:
        print("屏幕已开启不需要唤醒")


# 解锁屏幕
def unlock():
    # 获取锁屏状态
    key_guard = os.popen(
        "adb shell dumpsys window policy| findstr \"mShowingLockscreen\"").read().strip('\n').strip()
    if (key_guard.split(' ')[0]).split('=')[-1] == 'true':
        time.sleep(1)
        print("解锁屏保")
        # 左右滑动才好解锁,并且延迟100ms启动
        os.system('adb shell input swipe  340 865 370 202')
        time.sleep(1)
        print("输入密码")
        os.system('adb shell input tap 280 889')
        os.system('adb shell input tap 280 889')
        os.system('adb shell input tap 280 889')
        os.system('adb shell input tap 562 1611')
    else:
        print("屏幕已解锁不需要再次解锁")


# 打开APP
def open_app(app_name, app_activity):
    msg = os.popen(
        "adb shell ps | findstr " + app_name).read().strip('\n')
    if msg:
        print("APP已启动")
    else:
        os.system(
            'adb shell am start -n ' + app_name + app_activity)
        print("APP启动成功")


# 特定操作
def operating():
    os.system('adb shell input tap 294 1312')
    time.sleep(1)
    os.system('adb shell input tap 980 1829')
    time.sleep(2)
    os.system('adb shell input tap 374 1559')
    time.sleep(2)
    os.system('adb shell input tap 439 1417')
    flag = 0
    while flag < 20:
        time.sleep(2)
        os.system('adb shell input tap 189 1601')
        time.sleep(2)
        os.system('adb shell input tap 80 140')
        time.sleep(2)
        os.system('adb shell input swipe  340 865 370 202')
        flag = flag + 1


if __name__ == '__main__':
    wake_up()
    unlock()
    open_app("com.taobao.idlefish", "/com.taobao.fleamarket.home.activity.MainActivity")
    time.sleep(5)
    operating()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值