python中利用adb shell 控制手机,完美解决中文输入问题

1.连接手机, 打开开发者选项, 连接USB, (如果需要记录手机浏览的数据,下载安装,配置fiddler,  配置代理  参照我以前写的这个文章就行http://st4024589553.iteye.com/blog/2363667)  (当然你也可以安装一个模拟器来玩玩,一样的,可以操控多个模拟器)

2.要解决直接在APP输入中文,而不是打拼音,选汉字,这里需要为手机或者模拟器安装一个apk,就是一个老外写的输入法, 安装包我自己上传了,你们自己下载吧, 安装好后,在手机中进入 语言和输入法, 设置为默认输入法即可  (模拟器也是一样的)。


3.下载美团外卖APP,进入首页

代码================================如下:
# coding=utf-8
'''
python程序控制手机, 配置代理, 记录手机操作过程浏览的数据

@author: chenkai
'''
import os
import sys
import time

def main():
    #os.system("adb shell input keyevent 3")
    os.system("adb shell input tap 118 120")
    time.sleep(1)
    os.system("adb shell input tap 259 248")
    time.sleep(2)
    text="紫金大厦".encode('cp936')
    os.system("adb shell am broadcast -a ADB_INPUT_TEXT --es msg '"+text+"'")
    ##os.system("adb shell input text 'aa'")
    time.sleep(1)
    os.system("adb shell input tap 94 264")
    time.sleep(1)
    os.system("adb shell input tap 118 668")
    time.sleep(1)
    os.system("adb shell input swipe 432 1456 432 291")
    time.sleep(1)
    os.system("adb shell input tap 118 120")
    ''''开始第二次定位'''
    os.system("adb shell input tap 118 120")
    time.sleep(1)
    os.system("adb shell input tap 259 248")
    time.sleep(2)
    text="苏州街".encode('cp936') #必须转码,不然输入乱码
    os.system("adb shell am broadcast -a ADB_INPUT_TEXT --es msg '"+text+"'")
    ##os.system("adb shell input text 'aa'")
    time.sleep(1)
    os.system("adb shell input tap 94 264")
    time.sleep(1)
    os.system("adb shell input tap 118 668")
    time.sleep(1)
    os.system("adb shell input swipe 432 1456 432 291")
    time.sleep(1)
    os.system("adb shell input tap 118 120")
    
if __name__ == '__main__':
    main()
   

===============================操作说明
adb shell input text <string>
adb shell input keyevent <key code number or name>
adb shell input tap <x> <y>
adb shell input swipe <x1> <y1> <x2> <y2>
       
  1. keyevent指的是Android对应的keycode,比如home键的keycode=3,back键的keycode=4.
   

猜你喜欢

转载自st4024589553.iteye.com/blog/2377607
今日推荐