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.
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值