当前位置:网站首页>猿人学第七题
猿人学第七题
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)
边栏推荐
- What can breaking through the memory wall bring? See the actual battle of volcano engine intelligent recommendation service to save money and increase efficiency
- Online XML to CSV tool
- Understand what goals the MES system can achieve
- Learn some programming: anti unemployment "vaccine"
- Examples of map search
- 突破内存墙能带来什么?看火山引擎智能推荐服务节支增效实战
- I used annotations to configure the serialization of redis in one module project, and then introduced this module in another module. Why is this configuration
- 我在一个模块工程中使用注解配置了redis的序列化, 然后在另外一个模块引入这个模块,为什么这个配置
- PM's alarm: "NPM warn config global --global, --local are deprecated
- 基于Qt的软件框架设计
猜你喜欢

Okaleido tiger NFT is about to log in to binance NFT platform

How to realize the function of grabbing red envelopes in IM system?

从零实现深度学习框架——再探多层双向RNN的实现

Leetcode:51. queen n

SQL JOIN 入门使用示例学习左连接、内连接、自连接

String matching KMP

ASP. Net core deployment Manual: 1. Deployment Basics

微信公众号开发:素材管理(临时、永久)

QT notes - qtablewidget table spanning tree, qtreewidget tree node generates table content

6-16漏洞利用-rlogin最高权限登陆
随机推荐
QT notes - realize form adaptation
Why has API strategy become a magic weapon for enterprises' digital transformation?
[rust] Why do I suggest you learn rust | a preliminary study of rust
QWaitCondition 的正确使用方法
VMware virtual machine and vSphere migrate to each other
Buckle exercise - 35 combination sum II
有没有2、3w前期适合一个人干的创业项目呢?做自媒体可以吗?
Wechat applet learning five page Jump methods
SQL JOIN 入门使用示例学习左连接、内连接、自连接
QT based software framework design
微信小程序生成二维码
STM32 - Fundamentals of C language
QT notes - qtablewidget table spanning tree, qtreewidget tree node generates table content
Anaconda environment migration
Use abp Zero builds a third-party login module (III): web side development
String matching KMP
Please ask whether Oracle CDC does not support checkpointing. When the task is suspended and restarted during the real-time collection process, is the data changed
微信小程序-绘制仪表盘
[rust] rust language foundation | you should quickly get an impression when learning a language
Summary of MySQL database combined with actual SQL optimization of the project