On the way to destroy verification code

Universal codes 1

2 mask codes

3 machine learning to get verification code

4 use interface to extract payment market

 

Here to talk about the use of pay _ the Super Eagles, the need to use selenium library webdriver; need to use the images in Image processing pillow

Automatic identification codes 5 steps

1 call webdriver create browser and open the login page

2 as a whole intercept the login page (codes containing codes as part _ click automatic refresh static shots so identified)

3 recognizes page verification code element position and size where

Step 4 using the location and method Image deduct the full picture above screenshot

5 Super Eagles paid calling interface Screenshot recognition

Directly on the code

Import webdriver the Selenium from 
from PIL Import Image # Image processing library
from china_railway.captcha.chaojiying import Chaojiying_Client # import interface module name
import time

to create a Google browser #
Browser = webdriver.Chrome ()
# access the specified url
url = "HTTP: / /www.chaojiying.com/user/login/ "
browser.get (url)
# to enter a three-step verification code
# entire login page first step cut operating
browser.save_screenshot (" login.png ")
# Step this position is determined verification code (as a click on refresh, can not point to open the page to value) and matting
cap = browser.find_element_by_xpath ( "/ html / body / div [3] / div / div [3] / div [ 1] / form / div / img ") # codes page element
location = cap.location # determines that the verification of the location code
size = cap.size # codes determined size
# top left four points determining a right down (with the desktop display scale related, if it is 125%, all data were amplified 1.25)
left lOCATION = [ "X"] # front page four points to a predetermined position, the upper left corner of the initial point
up = LOCATION [ "Y"]
right = left + size [ 'width'] # Initial L + element width
down = up + size [ 'height '] # Initial + element height
var = (left, up, right , down )
# third step complete theme cap, according to the positioning matting codes and identification codes for the call interface
login_cap Image.open = ( 'login.png')
captcha = login_cap.crop (var)
captcha.save ( 'captcha .png ')
# super eagles call interface, and extracted digital send_keys operation
chaojiying = Chaojiying_Client (' accounts ',' password ',' 899836 ') ID # users generate a replacement software >> 96001
IM = Open (' captcha.png ',' rb '). read () # local image file path to replace the WIN system sometimes need a.jpg //
RES = chaojiying.PostPic (IM, 1902) # 1902 verification code type the official website >> price system after version 3.4+ print to add ()
browser.find_element_by_xpath ( "/html/body/div[3]/div/div[3]/div[1]/form/p[3]/input").send_keys(res['pic_str ']) # input interface verification code read

browser.find_element_by_xpath ( "/ html / body / div [3] / div / div [3] / div [1] / form / p [4] / input"). click () # click the login button
# Jump take time Chou Chou is nothing wrong with the naked eye, automation do assert
the time.sleep (5)
browser.close ()

 

 

 

 

 

 

 

Interface documentation as follows, on their own account need to apply for official use after recharge

import requests
from hashlib import md5

class Chaojiying_Client(object):

def __init__(self, username, password, soft_id):
self.username = username
password = password.encode('utf8')
self.password = md5(password).hexdigest()
self.soft_id = soft_id
self.base_params = {
'user': self.username,
'pass2': self.password,
'softid': self.soft_id,
}
self.headers = {
'Connection': 'Keep-Alive',
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
}

def PostPic(self, im, codetype):
"""
im: 图片字节
codetype: 题目类型 参考 http://www.chaojiying.com/price.html
"""
params = {
'codetype': codetype,
}
params.update(self.base_params)
files = {'userfile': ('ccc.jpg', im)}
r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
return r.json()

def ReportError(self, im_id):
"""
im_id:报错题目的图片ID
"""
params = {
'id': im_id,
}
params.update(self.base_params)
requests.post = R & lt ( 'http://upload.chaojiying.net/Upload/ReportError.php', Data = the params, headers = self.headers)
return r.json ()


IF the __name__ == '__main__':
chaojiying = Chaojiying_Client ( 'username', 'password', '899836') # >> user Center software generates a replacement ID 96001
IM = Open ( 'yzm.png', 'rb'). the Read () # local image file path WIN system sometimes need to replace a.jpg //
RES = chaojiying.PostPic (IM, 1902) # 1902 type the verification code after the official website >> price system version 3.4+ print to add ()
Print (RES [ 'pic_str'])

Guess you like

Origin www.cnblogs.com/digitalNatives/p/10963409.html