巨烂无比adb
# -*- coding: utf-8 -*- import os import time import random import datetime import requests import base64 import aircv as ac import pandas as pd info={'gov_name':[],'gov_wnum':[],'type':[],'come':[],'gov_info':[]} # 政府坐标集 gov_zb = [] # 事业单位坐标集 inst_zb = [] # 截图保存 def save_img(): # 图片名称以16位时间戳命名 imgname = str(time.time()).replace('.', '') os.system("adb shell /system/bin/screencap -p /sdcard/%s.png" % imgname) os.system("adb pull /sdcard/%s.png C:/Users/qichacha/Desktop/pythonProject/adb册数/getimg" % imgname) return "getimg/%s.png" % imgname # 搜索信息集 def search(local_name): # 切换为adb输入法 os.system('adb shell ime set com.android.adbkeyboard/.AdbIME') time.sleep(0.5) # 输入区域名称 os.system('adb shell am broadcast -a ADB_INPUT_TEXT --es msg %s' % local_name) # 切换为百度输入法 os.system('adb shell ime set com.baidu.input_vivo/.ImeVivoService') time.sleep(0.5) # 点击输入框 os.system('adb shell input tap 100 100') # 点击搜索 os.system('adb shell input tap 1000 2200') os.system('adb shell ime set com.android.adbkeyboard/.AdbIME') # 政府,事业单位,下滑截止 检测函数 def matchImg(imgsrc, imgobj, confidencevalue=0.95): # imgsrc=原始图像,imgobj=待查找的图片 imsrc = ac.imread(imgsrc) imobj = ac.imread(imgobj) match_result = ac.find_all_template(imsrc, imobj, confidencevalue) return match_result # 百度识图接口调用用于公众号中的微信号解析提取 def sbwz(imgs): # s = '20220425130812.png' gz_info='' request_url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic" f = open(imgs, 'rb') img = base64.b64encode(f.read()) params = {"image": img} access_token = '24.652dd92e83ce13a0d72ccee9858656a2.2592000.1652248080.282335-24065278' request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/x-www-form-urlencoded'} response = requests.post(request_url, data=params, headers=headers) try: if response: for i in response.json()['words_result']: gz_info = gz_info + i['words'] + '\n' # print(gz_info) return gz_info except Exception: pass def main(s): if len(matchImg(s, 'postimg/switch_end.png')) < 1: # 政府坐标获取 点击获取信息 coordinates = matchImg(s, 'postimg/gov.png') # 坐标解析 for coordinate in coordinates: coordinate = coordinate['result'] os.system('adb shell input tap %s' % (str(coordinate[0]) + ' ' + str(coordinate[1]))) # 点击识别到的坐标 time.sleep(0.3) # 识别>的坐标 second_zbs = matchImg(save_img(), 'postimg/insertimg.png') second_zb = second_zbs[0]['result'] os.system('adb shell input tap %s' % (str(second_zb[0]) + ' ' + str(second_zb[1]))) # 点击识别到的坐标 # 扫描文档文字输出 time.sleep(0.4) # 解析后的全部数据 infos = sbwz(save_img()) try: info['gov_wnum'].append(str(infos).split('微信号')[1].split('认证类型')[0]) info['gov_info'].append(infos) info['gov_name'].append(i) info['type'].append(str(infos).split('认证类型')[1].split('认证主体')[0]) info['come'].append(str(infos).split('认证类型')[1].split('认证主体')[1]) except: info['gov_wnum'].append('NUll') info['gov_info'].append('NUll') info['gov_name'].append(1) info['type'].append(s) info['come'].append('NUll') os.system('adb shell input keyevent 4') os.system('adb shell input keyevent 4') time.sleep(0.2) # 事业单位坐标获取 coordinates1 = matchImg(s, 'postimg/inst.png') # 坐标解析 for coordinate1 in coordinates1: coordinate1 = coordinate1['result'] os.system('adb shell input tap %s' % (str(coordinate1[0]) + ' ' + str(coordinate1[1]))) # 点击识别到的坐标 time.sleep(0.3) # 识别>的坐标 second_zbs = matchImg(save_img(), 'postimg/insertimg.png') second_zb = second_zbs[0]['result'] os.system('adb shell input tap %s' % (str(second_zb[0]) + ' ' + str(second_zb[1]))) # 点击识别到的坐标 # os.system('adb shell input keyevent 4') # os.system('adb shell input keyevent 4') # 扫描文档文字输出 time.sleep(0.4) # 解析后的全部数据 infos = sbwz(save_img()) try: info['gov_wnum'].append(str(infos).split('微信号')[1].split('认证类型')[0]) info['gov_info'].append(infos) info['gov_name'].append(i) info['type'].append(str(infos).split('认证类型')[1].split('认证主体')[0]) info['come'].append(str(infos).split('认证类型')[1].split('认证主体')[1]) except: info['gov_wnum'].append('NUll') info['gov_info'].append('NUll') info['gov_name'].append(1) info['type'].append(s) info['come'].append('NUll') os.system('adb shell input keyevent 4') os.system('adb shell input keyevent 4') time.sleep(0.2) # 坐标滑动 对应关系 起始横坐标 起始纵坐标 结束横坐标 结束纵坐标 花费时间毫秒 os.system('adb shell input swipe 340 2048 340 200 1000') time.sleep(0.4) return main(save_img()) # bug处理函数 def first_page(s): if len(matchImg(s, 'postimg/searchmore.png')) != 0: more = matchImg(s, 'postimg/searchmore.png') os.system('adb shell input tap %s' % (str(more[0]['result'][0]) + ' ' + str(more[0]['result'][1]))) # print('asdasdasdasdasdasdasdasdasdasdas',s,(str(more[0]['result'][0]) + ' ' + str(more[0]['result'][1]))) # if len(matchImg(s, 'postimg/switch_end.png')) < 1: # 政府坐标获取 点击获取信息 coordinates = matchImg(s, 'postimg/gov.png') # 坐标解析 for coordinate in coordinates: coordinate = coordinate['result'] os.system('adb shell input tap %s' % (str(coordinate[0]) + ' ' + str(coordinate[1]))) # 点击识别到的坐标 time.sleep(0.3) # 识别>的坐标 second_zbs = matchImg(save_img(), 'postimg/insertimg.png') second_zb = second_zbs[0]['result'] os.system('adb shell input tap %s' % (str(second_zb[0]) + ' ' + str(second_zb[1]))) # 点击识别到的坐标 # 扫描文档文字输出 time.sleep(0.6) # 解析后的全部数据 infos = sbwz(save_img()) try: info['gov_wnum'].append(str(infos).split('微信号')[1].split('认证类型')[0]) info['gov_info'].append(infos) info['gov_name'].append(i) info['type'].append(str(infos).split('认证类型')[1].split('认证主体')[0]) info['come'].append(str(infos).split('认证类型')[1].split('认证主体')[1]) except: info['gov_wnum'].append('NUll') info['gov_info'].append('NUll') info['gov_name'].append(1) info['type'].append(s) info['come'].append('NUll') os.system('adb shell input keyevent 4') os.system('adb shell input keyevent 4') time.sleep(0.2) # 事业单位坐标获取 coordinates1 = matchImg(s, 'postimg/inst.png') # 坐标解析 for coordinate1 in coordinates1: coordinate1 = coordinate1['result'] os.system('adb shell input tap %s' % (str(coordinate1[0]) + ' ' + str(coordinate1[1]))) # 点击识别到的坐标 time.sleep(0.3) # 识别>的坐标 second_zbs = matchImg(save_img(), 'postimg/insertimg.png') second_zb = second_zbs[0]['result'] os.system('adb shell input tap %s' % (str(second_zb[0]) + ' ' + str(second_zb[1]))) # 点击识别到的坐标 # 扫描文档文字输出 time.sleep(0.4) # 解析后的全部数据 infos = sbwz(save_img()) try: info['gov_wnum'].append(str(infos).split('微信号')[1].split('认证类型')[0]) info['gov_info'].append(infos) info['gov_name'].append(i) except: info['gov_wnum'].append('NUll') info['gov_info'].append('NUll') info['gov_name'].append(i) os.system('adb shell input keyevent 4') os.system('adb shell input keyevent 4') time.sleep(0.2) # 坐标滑动 对应关系 起始横坐标 起始纵坐标 结束横坐标 结束纵坐标 花费时间毫秒 return main(save_img()) def last_page(s): # if len(matchImg(s, 'postimg/searchmore.png')) != 0: # more = matchImg(s, 'postimg/searchmore.png') # os.system('adb shell input tap %s' % (str(more[0]['result'][0]) + ' ' + str(more[0]['result'][1]))) # print('asdasdasdasdasdasdasdasdasdasdas',s,(str(more[0]['result'][0]) + ' ' + str(more[0]['result'][1]))) # if len(matchImg(s, 'postimg/switch_end.png')) < 1: # 政府坐标获取 点击获取信息 coordinates = matchImg(s, 'postimg/gov.png') # 坐标解析 for coordinate in coordinates: coordinate = coordinate['result'] os.system('adb shell input tap %s' % (str(coordinate[0]) + ' ' + str(coordinate[1]))) # 点击识别到的坐标 time.sleep(0.3) # 识别>的坐标 second_zbs = matchImg(save_img(), 'postimg/insertimg.png') second_zb = second_zbs[0]['result'] os.system('adb shell input tap %s' % (str(second_zb[0]) + ' ' + str(second_zb[1]))) # 点击识别到的坐标 # 扫描文档文字输出 time.sleep(0.6) # 解析后的全部数据 infos = sbwz(save_img()) try: info['gov_wnum'].append(str(infos).split('微信号')[1].split('认证类型')[0]) info['gov_info'].append(infos) info['gov_name'].append(i) info['type'].append(str(infos).split('认证类型')[1].split('认证主体')[0]) info['come'].append(str(infos).split('认证类型')[1].split('认证主体')[1]) except: info['gov_wnum'].append('NUll') info['gov_info'].append('NUll') info['gov_name'].append(1) info['type'].append(s) info['come'].append('NUll') os.system('adb shell input keyevent 4') os.system('adb shell input keyevent 4') time.sleep(0.2) # 事业单位坐标获取 coordinates1 = matchImg(s, 'postimg/inst.png') # 坐标解析 for coordinate1 in coordinates1: coordinate1 = coordinate1['result'] os.system('adb shell input tap %s' % (str(coordinate1[0]) + ' ' + str(coordinate1[1]))) # 点击识别到的坐标 time.sleep(0.3) # 识别>的坐标 second_zbs = matchImg(save_img(), 'postimg/insertimg.png') second_zb = second_zbs[0]['result'] os.system('adb shell input tap %s' % (str(second_zb[0]) + ' ' + str(second_zb[1]))) # 点击识别到的坐标 # 扫描文档文字输出 time.sleep(0.4) # 解析后的全部数据 infos = sbwz(save_img()) try: info['gov_wnum'].append(str(infos).split('微信号')[1].split('认证类型')[0]) info['gov_info'].append(infos) info['gov_name'].append(i) except: info['gov_wnum'].append('NUll') info['gov_info'].append('NUll') info['gov_name'].append(i) os.system('adb shell input keyevent 4') os.system('adb shell input keyevent 4') time.sleep(0.2) # 坐标滑动 对应关系 起始横坐标 起始纵坐标 结束横坐标 结束纵坐标 花费时间毫秒 return 'end_over' if __name__ == '__main__': # s = str(save_img()) # print('s',s) with open('setting.txt', encoding='gbk') as f: for i in f: try: i = i.strip('\n') search(i) s = str(save_img()) # x = len(matchImg(s, 'postimg/exit.png')) # os.system('adb shell input tap 881.5 173.0') time.sleep(0.4) first_page(s) last_img= str(save_img()) print('sajkdghgkdsagfasgdfgjaskdgfasgjfgasdj',last_img) last_page(last_img) except: pass os.system('adb shell input tap 881.5 173.0') try: df = pd.DataFrame(info).to_excel(i+'1.xlsx') except: print(info)