前言

1
aHR0cDovL3h4ZmIubXdyLmNuL3NxX3pkeXNxLmh0bWw=

开始

1
先请求数据看看发现字体混乱

1

1
那么我们先请求接口拿数据
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

import json
import requests

cookies = {
}

headers = {

}

response = requests.post('http://xx.cn/OTMtiovshHolxmm/OTMnxmphjCovghAezg', cookies=cookies, headers=headers,
verify=False)
data = response.json()

if data.get("message") == "ok":
for i, item in enumerate(data.get("result", []), 1):
print(f"\n第 {i} 条数据")
for key in ("addvnm", "bsnm", "idNo", "rvnm", "stnm"):
print(f"{key}: {item.get(key, '')}")

with open("water_data.json", "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)

print("\n已保存到 water_data.json")
else:
print("接口返回异常:", data)

1

1
因为字体是经过处理反爬的我们可以搜索font-face得到关键js

1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function addCss(id) {
var preloadElement = document.createElement("link");
preloadElement.rel = "preload";
preloadElement.href = "/ttf/" + id + ".ttf";
preloadElement.as = "font";

document.getElementsByTagName("head")[0]
.appendChild(preloadElement);

var cssCode = "@font-face{ font-display:block; font-family : 'cfg_" + id
+ "'; src:url('/ttf/" + id + ".eot'); src:url('/ttf/" + id
+ ".eot?#iefix') format('embedded-opentype'),url('/ttf/" + id
+ ".ttf') format('truetype'); }";
}
1
js中的字体URL拼接   preloadElement.href = "/ttf/" + id + ".ttf"; 拼接URL得到相应的ttf文件,接着映射
字体编码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests
from fontTools.ttLib import TTFont
from io import BytesIO

BASE = "http://xx.cn"

#根据接口修改
sample = "#SZVVbBNKl6_1791510247091otltag䘚䘖䘠#FontTag"

# 提取字体文件名
font_id = sample.split("otltag", 1)[0].lstrip("#")
font_url = f"{BASE}/ttf/{font_id}.ttf"

print("字体标识:", font_id)
print("字体地址:", font_url)

response = requests.get(font_url, timeout=15)
print("HTTP 状态:", response.status_code)
response.raise_for_status()

font = TTFont(BytesIO(response.content))

with open("water_font.ttf", "wb") as f:
f.write(response.content)

print("字体已保存为 water_font.ttf")

cmap = {}
for table in font["cmap"].tables:
if table.isUnicode():
cmap.update(table.cmap)

print("Unicode 映射数量:", len(cmap))
print("全部字形映射:")

for codepoint, glyph_name in sorted(cmap.items()):
print(f"U+{codepoint:04X} {chr(codepoint)} {glyph_name}")

字体字典
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from pathlib import Path
from io import BytesIO
import math

import requests
from fontTools.ttLib import TTFont
from PIL import Image, ImageDraw, ImageFont

BASE = "http://xx.cn"
sample = "#SZVVbBNKl6_1791510247091otltag䘚䘖䘠#FontTag"

# 获取字体
font_id = sample.split("otltag", 1)[0].lstrip("#")
url = f"{BASE}/ttf/{font_id}.ttf"

response = requests.get(url, timeout=20)
response.raise_for_status()

font_path = Path("water_font.ttf")
font_path.write_bytes(response.content)

# 提取 Unicode 映射
font = TTFont(BytesIO(response.content))
cmap = {}

for table in font["cmap"].tables:
if table.isUnicode():
cmap.update(table.cmap)

items = sorted(cmap.items())
print("字形总数:", len(items))

# 每页最多 100 个,避免图片过大
cols = 5
cell_w = 180
cell_h = 130
page_size = 100

glyph_font = ImageFont.truetype(str(font_path), 58)
label_font = ImageFont.truetype("arial.ttf", 15)

output_dir = Path("font_atlas_pages")
output_dir.mkdir(exist_ok=True)

for start in range(0, len(items), page_size):
page_items = items[start:start + page_size]
rows = math.ceil(len(page_items) / cols)

image = Image.new(
"RGB", (cols * cell_w, rows * cell_h), "white"
)
draw = ImageDraw.Draw(image)

for i, (codepoint, glyph_name) in enumerate(page_items):
x = (i % cols) * cell_w
y = (i // cols) * cell_h

draw.rectangle(
(x, y, x + cell_w - 1, y + cell_h - 1),
outline="#cccccc"
)

# 使用自定义字体绘制特殊字符
draw.text(
(x + 55, y + 5),
chr(codepoint),
font=glyph_font,
fill="black"
)

draw.text(
(x + 8, y + 78),
f"U+{codepoint:04X}",
font=label_font,
fill="blue"
)

draw.text(
(x + 8, y + 100),
f"{glyph_name} 编号:{start + i + 1}",
font=label_font,
fill="black"
)

page_no = start // page_size + 1
output = output_dir / f"page_{page_no:02d}.png"
image.save(output)
print("已生成:", output.resolve())

print("全部完成。请打开 font_atlas_pages 文件夹查看图片。")

1

1

1

1
2
3
4
5
6
7
8
function extractFont(value) {
var pattern = new RegExp(
"(?:#)[a-zA-Z0-9_]*?(?=otltag)", "g"
);
var rets = pattern.exec(value);
// ...
return ft;
}//js中的正则
1
先请求接口再提取字体标识例如#SZVVbBNKl6_1791510247091otltag䘚䘖#FontTag,生成图片之后就可以弄对应了。