之前看到爬虫攻防之前端策略简析中提到猫眼电影的今日票房栏为自定义字体,但是博客中提到使用fonttools进行加载然后人工先把几个数字的座标点进行标记,然后每次刷新时,拿到新的woff字体时,通过fonttool将字体转换成xml格式,根据座标点信息,判断其uncode值分别是多少。然后再将代码中的“方框”转换成真实数字。
感觉这样比较麻烦,于是想通过转为图片然后进行识别得到数字,代码如下
from reportlab.graphics import renderPM
from reportlab.graphics.shapes import Group, Drawing, scale
path = 'E:/pycharm_workplace/black_list/d2080.woff'
font = TTFont(path) # it would work just as well with fontTools.t1Lib.T1Font
glyf = font['glyf']
for glyphName in glyf.keys():
imageFile = "%s.png" % glyphName
gs = font.getGlyphSet()
pen = ReportLabPen(gs, Path(fillColor=colors.black, strokeWidth=1))
g = gs[glyphNa