admin管理员组文章数量:1594754
找到源代码里面的 .woff 字体文件,下载下来,下面的代码转换为原来的映射
字体文件是二进制的
from fontTools.ttLib import TTFont
def get_cmap(self,font_nums):
"""
分析字体所映射的值
:param font_nums: 当前页面获取到的数组
:return:
"""
num_str = ''
# 读取字体
font = TTFont("font.woff")
# 生存成xml文件 酿成python可读,举行分析
font.saveXML('font.xml')
# 读取映射表
best_cmap = font['cmap'].getBestCmap()
best_glpy = font['cmap'].tables[2].ttFont.getReverseGlyphMap()
temp_cmap = dict()
for key, value in best_cmap.items():
temp_cmap[chr(key)] = value
for ns in font_nums :
for n in ns :
num_str += str((best_glpy[temp_cmap[n]] - 2))
self.all_num += int(num_str)
num_str = ''
读取后的方法,可以对照 xml 文件方便查看:
# 读取字体
font = TTFont("font.woff")
# 生存成xml文件 酿成python可读,举行分析
font.saveXML('font.xml')
"""
获得 name 属性,返回列表
<GlyphOrder>
<GlyphID id="0" name=".notdef"/>
...
</GlyphOrder>
"""
font.getGlyphOrder()
"""
获得 code : name ,返回字典,键的值需要用 chr() 转换一下
<map name="cid00019" code="0x30"/>
...
"""
best_cmap = font['cmap'].getBestCmap()
"""
获得 name : id,返回字典
<GlyphOrder>
<GlyphID id="0" name=".notdef"/>
...
</GlyphOrder>
"""
best_glpy = font['cmap'].tables[2].ttFont.getReverseGlyphMap()
总结:
爬到网页的字符 :name
name :code
先获取 <GlyphOrder> 对应的映射,在获取 <cmap> 里面的映射来找对应关系
版权声明:本文标题:字体反爬,下载 .woff 文件 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1728200838a1149353.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论