mirror of
https://github.com/luzhisheng/js_reverse.git
synced 2025-04-20 01:34:55 +08:00
猿人学第8题-验证码图文点选
This commit is contained in:
parent
33341fab48
commit
e45500c559
35
猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/gan_rao_xian.py
Normal file
35
猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/gan_rao_xian.py
Normal file
@ -0,0 +1,35 @@
|
||||
from PIL import Image
|
||||
import numpy as np
|
||||
import cv2
|
||||
|
||||
|
||||
# 将部分像素值变为纯白色, r1, g1, b1 对应的rgb值
|
||||
def turn_white(img, r1, g1, b1):
|
||||
for i in range(img.size[0]):
|
||||
for j in range(img.size[1]):
|
||||
r, g, b = img.getpixel((i, j))
|
||||
if r == r1 and g == g1 and b == b1:
|
||||
img.putpixel((i, j), (255, 255, 255))
|
||||
|
||||
|
||||
def processing_image(img_file, standard=205):
|
||||
""" 1.将图片进行降噪处理, 通过二值化去掉后面的背景色并加深文字对比度 """
|
||||
img = Image.open(img_file)
|
||||
|
||||
# np.unique()该函数是去除数组中的重复数字,并进行排序之后输出,这里返回的是所有像素rgb值,以及对应的数量
|
||||
# colors, counts = np.unique(np.array(im).reshape(-1, 3), axis=0, return_counts=True)
|
||||
# ct = np.sort(counts)
|
||||
# top2_counts = ct[-2:].tolist()
|
||||
# print(np.array(im).reshape(-1, 3))
|
||||
|
||||
|
||||
return img
|
||||
|
||||
|
||||
def run():
|
||||
image_b = processing_image('./img/1.png')
|
||||
image_b.save('./img/1-test.png')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
37
猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/main.py
Normal file
37
猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/main.py
Normal file
@ -0,0 +1,37 @@
|
||||
from PIL import Image
|
||||
import re
|
||||
import base64
|
||||
import requests
|
||||
import time
|
||||
import json
|
||||
|
||||
|
||||
class YuanrenXuan(object):
|
||||
|
||||
def __init__(self):
|
||||
self.url = "https://match.yuanrenxue.cn/api/match/8_verify"
|
||||
self.sum_value = 0
|
||||
|
||||
def get_task(self, i):
|
||||
t = int(time.time()) * 1000
|
||||
req = requests.get(self.url)
|
||||
img = re.findall(r'<img src="(.*)" alt="">', req.json().get('html'))[0]
|
||||
img = img.replace('data:image/jpeg;base64,', '')
|
||||
print(img)
|
||||
page_content = base64.b64decode(img)
|
||||
with open('img/1.png', 'wb') as f:
|
||||
f.write(page_content)
|
||||
exit()
|
||||
return req.text
|
||||
|
||||
def run(self):
|
||||
for i in range(1, 6):
|
||||
res_dict = json.loads(self.get_task(i))
|
||||
for j in res_dict.get('data'):
|
||||
self.sum_value += j.get('value')
|
||||
print(self.sum_value)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
a = YuanrenXuan()
|
||||
a.run()
|
Loading…
x
Reference in New Issue
Block a user