加密数字文字的爬取

爬取起点的数据信息,其中数字是加密的,需要下载包pip install fonttools

from fontTools.ttLib import TTFont
font.getBestCmap()
import requests
import re
from lxml import etree
from fontTools.ttLib import TTFont
from io import BytesIO

url = 'https://book.qidian.com/info/1012932890'
headers = {
	'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36',
}
r = requests.get(url=url, headers=headers)

tree = etree.HTML(r.text)
# 先拿到span的class名字
classname = tree.xpath('//div[contains(@class,"book-info")]/p/em/span/@class')[0]
# 拼接得到字体的url
font_url = 'https://qidian.gtimg.com/qd_anti_spider/{}.ttf'.format(classname)

# 得到span的内容
pattern = re.compile(r'<span class="' + classname + '">(.*?)</span>')
ret = pattern.search(r.text)
#    &#100301;&#100302;&#100297;&#100295;&#100304;
string = ret.group(1)

# 将字体文件下载下来
r_font = requests.get(url=font_url, headers=headers)
# filename = font_url.split('/')[-1]
# with open(filename, 'wb') as fp:
# 	fp.write(r_font.content)

# 打开这个字体
font = TTFont(BytesIO(r_font.content))
dic = font.getBestCmap()
# 关闭这个字体
font.close()

print(string)
print(dic)
font_dic = {'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9', 'zero': '0', 'period': '.'}
# 将string按照分号进行切割
lt = string.split(';')[:-1]
number = ''
for code in lt:
	code = code.lstrip('&#')
	char_code = dic[int(code)]
	number_code = font_dic[char_code]
	number += number_code
print(number)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值