导语:本文以春秋航空官网为例,实现账号自动批量注册,手机号短信收发使用的是吸码皇平台,对于滑块验证码破解需要详细了解的童鞋可以看本人的另一篇文章:Python Selenium破解滑块验证码最新版(GEETEST 95%以上通过率)
废话少说,上图例:
源码解析:
#--PANDA Edit--
from PIL import Image
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time,requests,random
class Verification_Code:
#匹配原图
def match_source(self,image):
imagea=Image.open('d://source1.png')
imageb=Image.open('d://source2.png')
imagec=Image.open('d://source3.png')
imaged=Image.open('d://source4.png')
list=[imagea,imageb,imagec,imaged]
#通过像素差遍历匹配本地原图
for i in list:
pixel1 = image.getpixel((868, 340))
pixel2 = i.getpixel((868, 428))
if abs(pixel1[0]-pixel2[0])<5:
return i
return image
#对比RGB值得到缺口位置
def is_similar(self,image1,image2,x,y):
pixel1 = image1.getpixel((x, y + 88))
pixel2 = image2.getpixel((x, y))
if abs(pixel1[0] - pixel2[0]) >= 50 and abs(pixel1[1] - pixel2[1]) >= 50 and abs(pixel1[2] - pixel2[2]) >= 50:
return False
return True
#计算滑块位移距离
def get_diff_location(self,image1,image2):
for i in range(825, 1082):
for j in range(335, 463):
if self.is_similar(image1,image2,i,j)==False:
return i
return -1
#滑块移动轨迹
def get_track(self,distance):
track=[]
current=0
mid=distance*7/8
t=random.randint(2,3)/10
v=0
while current3 and flag1==1: #判断多次循环后滑块验证码是否通过
self.cancelRecv(URL, token, phoneNumber)
flag0=0
break
#填入验证码进行注册
if flag0==1:
count = 1
while True:
messageContent = requests.get(URL,"action=getMessage&sid=987&phone=" + phoneNumber + "&token=" + token).text
# 截取头信息
header = messageContent[0:messageContent.index("|")]
#判断是否接收到验证码
if header == '0':
time.sleep(3.5)
if count > 5:
self.addBlacklist(URL, token, phoneNumber)
break
if header == '1':
messageInfo = messageContent[messageContent.index("|") + 1:len(messageContent)]
verificationCode = messageInfo[messageInfo.index("验证码:") + len("验证码:"):messageInfo.index(",",messageInfo.index("验证码:"))]
#填入验证码
driver.find_element_by_name('ValidateCode').send_keys(verificationCode)
#填入密码
driver.find_element_by_name('phonePassword').send_keys('wsk190120')
#确认密码
driver.find_element_by_name('phonePasswordConfirm').send_keys('wsk190120')
#点击注册
driver.find_element_by_id('dynamicRegist').click()
time.sleep(2)
#利用是否跳转页面判断是否成功注册
try:
driver.find_element_by_class_name('u-dialog-btn').click()
self.addBlacklist(URL, token, phoneNumber)
except:
print('注册成功')
f=open('d://output.txt','a+')
f.write('INSERT INTO map_chuser VALUES(null,'+'\''+phoneNumber+'\''+',\''+'wsk190120'+'\''+',0,0,1);'+'\n')
f.close()
break
count+=1
time.sleep(0.5)
driver.close()
#获取手机号码
def getPhone(self,URL,loginInfo,token):
phoneInfo = requests.get(URL, "action=getPhone&sid=987&token=" + token).text
return phoneInfo[loginInfo.index("|") + 1:len(loginInfo)]
#手机号码加黑
def addBlacklist(self,URL,token,phoneNumber):
requests.get(URL, "action=addBlacklist&sid=987&phone=" + phoneNumber + "&token=" + token)
#手机号码释放
def cancelRecv(self,URL,token,phoneNumber):
requests.get(URL,'action=cancelRecv&sid=987&phone='+phoneNumber+'&token='+token)
#生成随机密码
'''def random_str(self,randomlength):
str = ''
chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
length = len(chars) - 1
for i in range(randomlength):
str += chars[random.randint(0, length)]
return str'''
if __name__=='__main__':
auto_logon = Verification_Code()
URL = "http://www.ximahuang.com/alz/api"
for i in range(5):
try:
print(i)
#开发者登录吸码皇
loginInfo = requests.get(URL,b'action=loginIn&name=xtpa001&password=190120&developer=developer=df64aff97eb04560af80ba7834f4e6c9').text
#截取登录令牌
token = loginInfo[loginInfo.index("|") + 1:len(loginInfo)]
#获取用户信息
userInfo = requests.get(URL, "action=getSummary&token=" + token)
#获取手机号码
phoneNumber = auto_logon.getPhone(URL,loginInfo, token)
#获取验证码进行验证注册
auto_logon.run(URL,token,phoneNumber)
except:
print('注册提前结束!')
print('程序结束!')