当前位置:网站首页>猿人学第七题
猿人学第七题
2022-07-24 12:36:00 【consult one's pillow】
这题是一个字体映射
需要安装这个库来进行字体文件的解析
from fontTools.ttLib import TTFont
虽然每次请求都会更新字体文件,但是通过观察发现,每次的字体文件的坐标是不会变的。所以我们获取一个ttf文件,在本地做好映射就可以了
字体文件在响应的woff: "AAEAAAAKAIAAAwAgT1MvMgTkZQcAAAEoAAA这里,这个是个一个base64的字符串。base64就是将二进制变成字符串的一个东西。这里直接反解一下就可以了。
创建映射表的python代码
# 读取本地文件创建一个映射表
def creat_map(temp_path):
# 返回的映射列表、
response_map = {
}
font_map = {
}
# 加载字体文件:
font1 = TTFont('test1.ttf')
# 获取getGlyphOrder节点的name值,返回为列表
font_map[str(font1['glyf']['unib482'].flags)] = 0
font_map[str(font1['glyf']['unic462'].flags)] = 1
font_map[str(font1['glyf']['unie516'].flags)] = 2
font_map[str(font1['glyf']['unif157'].flags)] = 3
font_map[str(font1['glyf']['unif457'].flags)] = 4
font_map[str(font1['glyf']['unib215'].flags)] = 5
font_map[str(font1['glyf']['unie798'].flags)] = 6
font_map[str(font1['glyf']['unif491'].flags)] = 7
font_map[str(font1['glyf']['unie745'].flags)] = 8
font_map[str(font1['glyf']['unic894'].flags)] = 9
# print(font_map)
font2 = TTFont(temp_path)
# 获取全部名字
full_name = font2.getGlyphNames()
for name in full_name:
if name != '.notdef':
# 获取这个字体的坐标
bytearray_temp = str(font2['glyf'][name].flags)
# 获取这个字体映射的数字
response_map[name.replace('uni', '&#x')] = font_map[bytearray_temp]
return response_map
逻辑代码
headers = {
'authority': 'match.yuanrenxue.com',
'accept': 'application/json, text/javascript, */*; q=0.01',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
'cache-control': 'no-cache',
'cookie': 'Hm_lvt_c99546cf032aaa5a679230de9a95c7db=1658124371,1658194036,1658281030,1658368336; no-alert3=true; tk=4032565147326549623; sessionid=2hvat8s8c5iunzne5x0mzd10u4ku7x2x; Hm_lvt_9bcbda9cbf86757998a2339a0437208e=1658124374,1658194060,1658281037,1658368358; Hm_lpvt_9bcbda9cbf86757998a2339a0437208e=1658387284; Hm_lpvt_c99546cf032aaa5a679230de9a95c7db=1658387288',
'pragma': 'no-cache',
'referer': 'https://match.yuanrenxue.com/match/7',
'sec-ch-ua': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'yuanrenxue.project',
'x-requested-with': 'XMLHttpRequest',
}
calculator_score = 0
calculator_name = ""
for page in range(1, 6):
params = (
('page', page),
)
response = requests.get('https://match.yuanrenxue.com/api/match/7', headers=headers, params=params)
data = response.json()
data['parse_data'] = []
woff = data.get('woff')
with open('temp.ttf', 'wb') as f:
f.write(base64.b64decode(woff))
response_data = creat_map(temp_path='temp.ttf')
yyq = 1
for i in data.get('data'):
temp = ''
val = i.get('value').split(' ')
for j in val:
if j:
temp += str(response_data[j])
append_data = {
'value': int(temp), 'name': name[yyq + (page - 1) * 10]}
if append_data.get('value') > calculator_score:
calculator_score = append_data.get('value')
calculator_name = append_data.get('name')
data['parse_data'].append(append_data)
yyq += 1
print(data['parse_data'])
print(calculator_score)
print(calculator_name)
边栏推荐
- Intent jump pass list set
- Learning materials about red team
- Is there any entrepreneurship project suitable for one person in the early stage of 2W and 3W? Is it OK to be we media?
- leecode-268. 丢失的数字(异或的应用,找没有出现的数字,找只出现一次的数字)
- 【功能测试】项目的测试——登录和发布文章功能
- 树莓派自建 NAS 云盘之——数据自动备份
- 树莓派自建 NAS 云盘之——树莓派搭建网络存储盘
- 如何最快找出复杂代码运行时的函数调用流程
- Slow motion animation, window related data and operations, BOM operations [DOM (V)]
- Wechat applet generates QR code
猜你喜欢

6-16 vulnerability exploitation -rlogin maximum permission login

Microsoft SQL Server database language and function usage (XII)
![Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]](/img/ee/e0770298d0534014485145c434491a.png)
Detailed explanation of MSTP protocol for layer 3 switch configuration [Huawei ENSP experiment]

高速成长的背后,华为云乌兰察布数据中心的绿色之道

How to upload pictures from typora to CSDN

Day3: branch structure

Counter attack dark horse: devdbops training, give you the best courses!

thinkphp 实现数据库备份

如何最快找出复杂代码运行时的函数调用流程

Leetcode:51. queen n
随机推荐
How to find out the function calling process of complex code running as soon as possible
Counter attack dark horse: devdbops training, give you the best courses!
Try... Finally summary
Microsoft SQL Server database language and function usage (XII)
使用Jenkins搭建CI服务器
[leetcode]- linked list-3
QT | summary of the use of edit box
Is it safe for Huatai Securities to open a remote account? Is there any guarantee?
基于Qt的软件框架设计
How to eliminate the character set and sorting rules specially set for fields in MySQL tables?
Wechat applet generates QR code
Buckle practice - maximum number of 28 splices
How to render millions of 2D objects smoothly with webgpu?
Leecode-268. missing numbers (Application of XOR, find numbers that do not appear, find numbers that only appear once)
leetcode:51. N 皇后
iSCSI新应用,以及NFS的存储服务分离
QT notes - custom data types
泰山OFFICE技术讲座:段落边框的布局难点
Industry insight | how to better build a data center? It and business should "go together"
Qt Creator怎样更改默认构建目录