58是一个字体反爬相对简单的网站了,它只对数字进行了反爬处理。适合拿来做字体反爬入门。
先上代码,在详细记录,纯小白操作,不怕看不懂啊:
import requests
import base64
import re
from fontTools.ttLib import TTFont
# 获取参数,这里主要是返回的响应内容,及匹配到的font_face被base64编码的文件
def get_params(url):
resp = requests.get(url)
content = resp.text
# print(resp.text)
font_face = re.search("font-face{.*?base64,(.*?)'.*?}", content, re.S).group(1).strip()
# print(font_face)
return font_face, content
# 解base64编码,写入ttf字体文件
def parse_font_face(font_face):
font_face = base64.b64decode(font_face)
with open('58.ttf', 'wb') as f:
f.write(font_face)
font = TTFont('58.ttf')
font.saveXML('58.xml')
# 使用footTools自带的getBestCmap()获取映射
bestcmap = font['cmap'].getBestCmap()
# print(bestcmap)
# 创建新的映射关系字典
newmap = dict()
for