字体反爬-起点月票
思路分析
1、得到该页面的所有月票数据
2、对月票url 发送请求 获取响应
3、提取字体文件的url,通过该url提取字体的关系映射表
4、保存数据
“”"
import re
import requests
from fontTools.ttLib import TTFont
from io import BytesIO
from lxml import etree
代码实现:
1、确定url
base_url = 'https://www.qidian.com/rank/yuepiao'
2、构建请求头
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36'
,
'referer': 'https://www.qidian.com/rank'
,
'cookie': 'e1=%7B%22pid%22%3A%22qd_P_rank_19%22%2C%22eid%22%3A%22%22%2C%22l1%22%3A5%7D; e2=%7B%22pid%22%3A%22qd_P_rank_19%22%2C%22eid%22%3A%22%22%2C%22l1%22%3A5%7D; _csrfToken=BnhREF5ih538gczHjZfLlPHPVizX7VPUasM3nJ6g; newstatisticUUID=1620827924_867497743; _yep_uuid=7e4bf842-f915-978c-af83-07a16f41beac; e1=%7B%22pid%22%3A%22qd_P_rank_01%22%2C%22eid%22%3A%22qd_C45%22%2C%22l1%22%3A5%7D; e2=%7B%22pid%22%3A%22qd_P_rank_01%22%2C%22eid%22%3A%22%22%2C%22l1%22%3A5%7D'
}
3、发送请求获取响应
response = requests.get(base_url, headers=headers)
print(response.content.decode()) # 结果中没有所需要的内容
4、从响应内容中提取字体加密文件的url 正则表达式