↑↑↑点击上方“蓝字”,关注“极客猴”html
若是你喜欢极客猴,能够把我置顶或加为星标python
阅读文本大概须要 6 分钟。正则表达式
没有了解过字体加密的小伙伴能够先看看上一篇,本文与上一篇重复的部分就不细讲了。微信
咱们打开猫眼电影票房榜单的首页app
https://maoyan.com/board/1函数
很明显,猫眼电影的榜单进行了字体加密。学习
#.woff文件转换成.xml文件
from fontTools.ttLib import TTFont
font = TTFont('./.woff')
font.saveXML('A.xml')
#对比两个坐标的差别
def compare(AA, BB):
for i in range(5):
if abs(AA[i][0] - BB[i][0]) < 80 and abs(AA[i][1] - BB[i][1]) < 80:
pass
else:
return False
return True
#True则可视为是同一个字
# 字体解密
def modify_html(newFont, html):
basefont = TTFont('./base_font.woff')
unilist = newFont['cmap'].tables[0].ttFont.getGlyphOrder()
numlist = []
base_num = ['6', '3', '7', '1', '5', '9', '0', '4', '2', '8']
base_unicode = ['uniF0DA', 'uniE907', 'uniED01', 'uniEAE1', 'uniF206',
'uniE455', 'uniF401', 'uniE19C', 'uniEB76', 'uniF855']
for i in range(1, len(unilist)):
newGlyph = newFont['glyf'][unilist[i]].coordinates
for j in range(len(base_unicode)):
baseGlyph = basefont['glyf'][base_unicode[j]].coordinates
if compare(newGlyph,baseGlyph):
numlist.append(base_num[j])
break
rowList = []
for i in unilist[2:]:
i = i.replace('uni', '&#x').lower() + ";"
rowList.append(i)
dictory = dict(zip(rowList, numlist))
for key in dictory:
if key in html:
html = html.replace(key, str(dictory[key]))
return html
# 返回解密后的html
# 正则
def parse_page(html):
pattern = re.compile('
.*?board-index-.*?>(.*?).*?src="(.*?)".*?'
+ 'title="(.*?)".*?class="star">(.*?)字体
.*?releasetime">(.*?)flex
.*?'
+ 'realtime".*?stonefont">(.*?).*?'
+ 'total-boxoffice".*?stonefont">(.*?).*?网站
'
, re.S)
items = re.findall(pattern, html)
data = pd.DataFrame(items,columns=['index','image','title','star','releasetime','realtime','total-boxoffice'])
data['star']=data['star'].str[3:]
data['releasetime']=data['releasetime'].str[5:]
print(data)
return data
运行一下。
get。
本文相关爬虫代码,仅供学习交流:https://t.zsxq.com/RVn6qBU

技术·思考·职场
长按二维码,添加关注!
本文分享自微信公众号 - 极客猴(Geek_monkey)。
若有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一块儿分享。