[51]网站滑块验证码还原
import requests
import re
from PIL import Image
import time
import hashlib
from fake_useragent import UserAgent
imgUrl = re.compile('background-image: url\((.*?)\)') #找到原图链接
positions = re.compile("class='gt_cut_fullbg_slice' style='background-position:(.*?)px (.*?)px;'>")#图片坐标
ua = UserAgent()
url='https://authcode.51.com/authcode/slidecode'
headers ={
'User-Agent': ua.random
}
params={
'callback': 'jQuery11110024185931707424446_1648388960494',
'from': 'passport',
'_': '1648388960512'
}
html=requests.get(url,headers=headers,params=params)
print('html.text->',html.text)
imgurls=imgUrl.findall(html.text)
for us in imgurls:
if 'big' in us:
bigImg='https:'+us.replace("\/",'/').replace('\\"','')
print('bigImg->',bigImg)
pos_lists=[]
positions=positions.findall(html.text)
for ps in positions:
x=int(ps)
y=int(ps)
pos_lists.append({"x":x,"y":y})
bg_img = requests.get(bigImg).content
with open('51原图.png','wb')as f:
f.write(bg_img)
#bg_img=io.BytesIO(bg_img)
im = Image.open('51原图.png')
new_pos=[]
for pos in pos_lists:
if pos['y'] == -75:
new_pos.append(im.crop((abs(pos['x']), 75, abs(pos['x']) + 13, 100)))
if pos['y'] == -50:
new_pos.append(im.crop((abs(pos['x']), 50, abs(pos['x']) + 13, 75)))
if pos['y'] == -25:
new_pos.append(im.crop((abs(pos['x']), 25, abs(pos['x']) + 13, 50)))
if pos['y'] == 0:
new_pos.append(im.crop((abs(pos['x']), 0, abs(pos['x']) + 13, 25)))
#print(new_pos)
#新图片
new_im = Image.new('RGB', (260, 100))
x_offset = 0
y_offset=0
for im in new_pos:
if (x_offset==260):
x_offset=0
y_offset+=25
new_im.paste(im, (x_offset, y_offset))
x_offset += 13
print('ok','{}.png'.format('resul'))
new_im.save('./{}.png'.format('51原图还原后'))
my_time = int(time.time()*1000)
times = re.compile('<inpu.*?times.*?value=(.*?)>')
times = times.findall(html.text).replace('\\"','')
challenge = re.compile('<inpu.*?challenge.*?value=(.*?)>')
challenge = challenge.findall(html.text).replace('\\"','')
# print(times)
# print(challenge)
point='68'
re_url = 'https://authcode.51.com/authcode/yz2'
params1 = {
'callback': f'jQuery111104273542489406337_'+str(my_time),
'point': point,
'times': times,
'challenge': challenge,
'token': hashlib.md5((challenge+times+point).encode('utf8')).hexdigest(),
'from': 'passport',
'divpre':'',
'_': str(my_time)
}
re_html = requests.get(re_url,params=params1)
print(re_html.text) 厉害的,感谢分享拖动验证方式 感觉很厉害 但是看不懂
大佬牛皮 大佬牛逼啊,新手看看 大佬牛皮 感谢分享 很好的思路,感谢! {:301_1003:}看了下代码,大佬是怎么找到规律的,这也太牛了 大佬牛皮
页:
[1]