Python crawls through ADB to pay treasure mobile end billing information __python

Source: Internet
Author: User

Python crawls the billing information for the Alipay mobile end through the ADB connection, and the process is as follows:

This file can then be decomposed into the following four main features:

1. Image recognition; 2. Analog clicks; 3. Simulate slide; 4. Screenshot function

I. Handling of Billing details page:

After the Bill details page screenshot, then choose to split with the picture, capture to 3 screenshots, respectively: Name field, billing Amount field; Billing Number field;

Two. Dealing with the bill's thumbnail pages:

How to handle the thumbnail page of the bill, at the beginning I was thinking, pass in a datum, and then go down a value of equal amount each time to click, get the data of the details page, but in this case, can only get one page at a time, and the condition of the traversal is not known, so I chose to read a piece of data on the downward scrolling method, To traverse the bill of each article;

Three. Screening of monthly bills:

When you choose to read a piece of data scrolling down, then add a judgment condition, that is, if the next screenshot and split the good picture if the "month" or "mesh" of the field, it will be judged as the end of the month, out of the loop, otherwise scroll down, and analog click;

#-*-coding:utf-8-*-import OS import math import matplotlib.pyplot as PLT import pytesseract from PIL import Image imp ORT time import CSV import numpy as NP import Matplotlib.image as Mpimg class Pay_ali:def __init__ (self): sel
        F._coefficient = 1.35 Self._click_count = 0 self._coords = [] #输出函数 def print_all (self,text): Print (text) print (' \ n ') # picture recognition def img_rec (self,img): Text = pytesseract.image_to_string (image  . Open (IMG), lang= ' Chi_sim ') # Print (type (text)) Self.print_all (text) return text #点击功能 def  Acquire_info (self,x1,y1): x1 = str (x1) y1 = str (y1) os.system (' adb shell input tap ' + x1 + ' +
        Y1) #滑动功能 def acquire_swipe (self,x1,y1,x2,y2): x1 = str (x1) y1 = str (y1) x2 = str (x2) y2 = str (y2) os.system (' adb shell input swipe ' + x1 + ' + y1+ ' ' +x2+ ' ' +y2 ') # screenshot feature def cut_info (SE Lf,path): Path = STR (PATH) # screenshot.png. Os.system (' adb shell screencap-p/sdcard/' +path) os.system (' adb pull/sdcard/' +path) # segmentation + recognition function def seg_in
        Fo (self,x1,y1,x2,y2,path,out_path): path = str (path) Out_path = str (out_path) # There are insufficient cases here, screenshots will cover
        img = image.open (path) region= (x1,y1,x2,y2) # Print (region) Cropimg = img.crop (region) Cropimg.save (out_path) Text = Self.img_rec (out_path) return text # show picture features Def img_show (SELF,SRC) : img = image.open (SRC) plt.imshow (img) plt.show () # Get the Month Information def acquire_info_month (self,st 
            art,end): # start+=262 while (End-start) >=: # start = = 262 Time.sleep (1) Self.cut_info (' screen2.png ') Text = Self.seg_info (23,start,200,start+250, ' screen2.png ', ' crop2.png ') if (Text.find (' month ') >=0 or text.find (' mesh ') >=0): # Self.acquire_swipe(23,start+300,23,start) Break Else:self.acquire_swipe (23,start+220,23,start)
            Self.acquire_info (240,start+100) time.sleep (1) self.cut_info (' Screen1.png ') Time.sleep (1) self.csv_save () time.sleep (1) self.acquire_info (302.8,2100.3) # will count  It is saved into CSV def csv_save (self): name = Self.seg_info (482, 258, 693, 332, ' screen1.png ', ' crop1.png ') money = Self.seg_info (305, 367, 747, 492, ' screen1.png ', ' crop1.png ') Money_info = Self.seg_info (20, 646, 1061, 1709, ' Screen1.png ', ' Crop1.png ') # Money_info = Self.seg_info (R, 646, 1061, 1709, ' screen1.png ', ' crop1.png ') OWS = [(Name,money,money_info)] with open (' pay_ali.csv ', ' a ') as F:f_csv = Csv.writer (f) F _csv.writerows (rows) # Run function def run (self): Self.acquire_info (972.8,1954.93) self.acquire_info (254 , 714) Self.acquiRe_info (240,732) time.sleep (1) self.cut_info (' Screen1.png ') time.sleep (1) # Self.seg_info (


        342.7, 364.2, 707.7, 489.6) # Self.seg_info (417,258,704,338) Self.csv_save () time.sleep (1) Self.acquire_info (302.8,2100.3) # self.img_show (' crop.png ') self.acquire_info_month (475,2023) if __name __ = = "__main__": Pay_ali = Pay_ali () pay_ali.run () # pay_ali.cut_info (' screen_test.png ') # Pay_ali.img_sh ow (' screen_test.png ')
The whole small demo implementation is not very difficult, now the problem lies in how to adapt to different models, welcome to shoot Bricks ~


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.