极验验证码的图片还原思路
1.获取图片地址
由上方的图片获取到图片的地址,完整链接需要地址前方+"https://static.geetest.com/"
请求图片之后得到混淆的图片
上方乱序的图片需要进行重组才会得到正常的图片,直接上代码:
下面展示一些 内联代码片
。
// A code block
var foo = 'bar';
def get_merge_image(imurl): # 传入带缺口信息的图片的地址
location_list = [{"x": -157, "y": -58}, {"x": -145, "y": -58}, {"x": -265, "y": -58}, {"x": -277, "y": -58},
{"x": -181, "y": -58}, {"x": -169, "y": -58}, {"x": -241, "y": -58}, {"x": -253, "y": -58},
{"x": -109, "y": -58}, {"x": -97, "y": -58}, {"x": -289, "y": -58}, {"x": -301, "y": -58},
{"x": -85, "y": -58}, {"x": -73, "y": -58}, {"x": -25, "y": -58}, {"x": -37, "y": -58},
{"x": -13, "y": -58}, {"x": -1, "y": -58}, {"x": -121, "y": -58}, {"x": -133, "y": -58},
{"x": -61, "y": -58}, {"x": -49, "y": -58}, {"x": -217, "y": -58}, {"x": -229, "y": -58},
{"x": -205, "y": -58}, {"x": -193, "y": -58}, {"x": -145, "y": 0}, {"x": -157, "y": 0},
{"x": -277, "y": 0}, {"x": -265, "y": 0}, {"x": -169, "y": 0}, {"x": -181, "y": 0},
{"x": -253, "y": 0}, {"x": -241, "y": 0}, {"x": -97, "y": 0}, {"x": -109, "y": 0},
{"x": -301, "y": 0}, {"x": -289, "y": 0}, {"x": -73, "y": 0}, {"x": -85, "y": 0},
{"x": -37, "y": 0}, {"x": -25, "y": 0}, {"x": -1, "y": 0}, {"x": -13, "y": 0},
{"x": -133, "y": 0}, {"x": -121, "y": 0}, {"x": -49, "y": 0}, {"x": -61, "y": 0},
{"x": -229, "y": 0}, {"x": -217, "y": 0}, {"x": -193, "y": 0}, {"x": -205, "y": 0}]
bg_img = self.sess.get(imurl, verify=False, timeout=3).content
bg_img = io.BytesIO(bg_img)
im = Image.open(bg_img)
im_list_upper = []
im_list_down = []
for location in location_list:
if location['y'] == -58:
im_list_upper.append(im.crop((abs(location['x']), 58, abs(location['x']) + 10, 116))) # 有关参数的介绍请看下方的crop方法的介绍, 可自行调整
if location['y'] == 0:
im_list_down.append(im.crop((abs(location['x']), 0, abs(location['x']) + 10, 0 + 58)))
new_im = Image.new('RGB', (260, 116)) # 生成的图片的大小, 可调整
x_offset = 0
for im in im_list_upper:
new_im.paste(im, (x_offset, 0))
x_offset += im.size[0]
x_offset = 0
for im in im_list_down:
new_im.paste(im, (x_offset, 58))
x_offset += im.size[0]
return new_im
# 将重组之后的图片进行返回 也可直接使用 new_im.save("./captcha.png") 保存
重组之后的图片为
crop方法
im.crop(box) ⇒ image
从当前的图像中返回一个矩形区域的拷贝。变量box是一个四元组,定义了左、上、右和下的像素坐标。用来表示在原始图像中截取的位置坐标,如box(100,100,200,200)就表示在原始图像中以左上角为坐标原点,截取一个100*100(像素为单位)的图像,为方便理解,如下为示意图box(b1,a1,b2,a2)
可以私信联系我,有整个流程的破解源码