From e45500c5594ccd8611271fd1d48244ae6e43f37c Mon Sep 17 00:00:00 2001 From: luzhisheng Date: Tue, 20 Jun 2023 01:08:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8C=BF=E4=BA=BA=E5=AD=A6=E7=AC=AC8=E9=A2=98-?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E5=9B=BE=E6=96=87=E7=82=B9=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../猿人学第8题-验证码图文点选/gan_rao_xian.py | 35 ++++++++++++++++++ .../猿人学第8题-验证码图文点选/main.py | 37 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/gan_rao_xian.py create mode 100644 猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/main.py diff --git a/猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/gan_rao_xian.py b/猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/gan_rao_xian.py new file mode 100644 index 0000000..60e3381 --- /dev/null +++ b/猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/gan_rao_xian.py @@ -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() \ No newline at end of file diff --git a/猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/main.py b/猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/main.py new file mode 100644 index 0000000..a7ed1c7 --- /dev/null +++ b/猿人学Web端爬虫攻防刷题平台/猿人学第8题-验证码图文点选/main.py @@ -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'', 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()