网址:https://match.yuanrenxue.cn/match/7

接口:https://match.yuanrenxue.cn/api/match/7?page=2

解析流程

直接抓包看接口, 返回的woff参数貌似是加密的,竟然是字体加密,那肯定会有个字体包,看一下字体接口

image-20230524163932953

果不其然,这是个woff参数拼接的就是这个字体包

image-20230524164124694

我们直接把字体包写入到本地

1
2
3
4
5
response = requests.get('https://match.yuanrenxue.cn/api/match/7?page={}'.format(i), cookies=cookies, headers=headers).json()
data_dict = response['data']
font_file = base64.b64decode(response['woff'])
with open('match_07.ttf', 'wb') as f:
f.write(font_file)

找个字体包在线解析的网站,看一下里面的内容是什么,很明显返回的接口deta值里面,对于的是字体包里面的数字

image-20230524164259747

因为字体包内容是动态的,所以我们需要把字体包下面的值取出来,把上面的数字写入到图片中,进行识别,这一块涉及到使用image模块对字体包的解析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
font = TTFont('match_07.ttf')  # 打开文件
code_list = font.getGlyphOrder()[1:] # 返回的是数字对于的编码
print(code_list)
# 创建图片
im = Image.new("RGB", (1800, 1000), (255, 255, 255))
dr = ImageDraw.Draw(im)
font = ImageFont.truetype('match_07.ttf', 40)

# 将字体写入图片
count = 3
array_list = numpy.array_split(code_list, count) # 将列表切分成15份,以便于在图片上分行显示
for t in range(count):
new_list = [i.replace("uni", "\\u") for i in array_list[t]]
text = "".join(new_list)
text = text.encode('utf-8').decode('unicode_escape')
dr.text((0, 50 * t), text, font=font, fill="#000000")
im.save("sss.jpg")

result = pytesseract.image_to_string(im, lang="chi_sim")
result = result.replace(" ", "").replace("\n", "")
code_list = [i.replace("uni", "&#x") for i in code_list]
code_dict = dict(zip(code_list, list(result)))
return code_dict

解析出来之后,就是一个字典,然后将接口返回的data 数值进行获取就可以了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
response = requests.get('https://match.yuanrenxue.cn/api/match/7?page={}'.format(i), cookies=cookies, headers=headers).json()
data_dict = response['data']
font_file = base64.b64decode(response['woff'])
with open('match_07.ttf', 'wb') as f:
f.write(font_file)
code_dict = write_img()
for data in data_dict:
value_list = data['value'].split(' ')[:-1]
lp = ''
for value in value_list:
num = code_dict[value]
lp += num
if int(lp) > max_lp:
max_lp = int(lp)
print(lp)
# print(value_list)

print(f"最大值是:{max_lp}")