# Individuals are original, please indicate the source: https://www.cnblogs.com/HugJun/p/11506270.html
import requests,time,re,pprint from fontTools.ttLib import TTFont from io import BytesIO def get_font(url): resp = requests.get(url) font = TTFont(BytesIO(resp.content)) web_font_relation = font.getBestCmap() font.close() return web_font_relation def get_html_info(url): headers = { 'User-Agent': 'User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36' } html_data = requests.get(url, headers=headers) url_ttf_pattern = re.compile('<style>(.*?)\s*</style>',re.S) fonturl = re.findall(url_ttf_pattern,html_data.text)[0] url_ttf = re.search('woff.*?url.*?\'(.+?)\'.*?truetype', fonturl).group(1) print(url_ttf) return url_ttf,html_data.text def get_encode_font(data,web_font_relation): """ The encrypted css letters replaced the original figures : param data: Background Source : return: "" " python_font_relation = { ' One ' :. 1 , ' TWO ' : 2 , ' Three ' :. 3 , ' Four ' :. 4 , ' Five ' :. 5 , ' Six ' :. 6 , ' Seven ' :. 7 , ' Eight ' :. 8 , 'nine':9, 'zero':0, 'period':'.' } for k,v in web_font_relation.items(): if str(k) in data: print(k,v) fon_css = '&#'+str(k)+';' data = re.sub(fon_css, str(python_font_relation[v]), data) total_num = int(float(''.join(re.findall('<span class = ". +" > (. +) </ span> </ em> <cite> words ' , Data))) * 10000) # total number of words total_recommend = int (a float ( '' .join (Re. findAll ( ' <span class =. "+"> (. +) </ span> </ EM> <auf cite> million total recommendation ' , Data))) * 10000) # total recommendation week_recommend = int (a float ( '' .join (the re.findall ( ' <= span class. "+"> (. +) </ span> </ EM> <auf cite> weeks recommended ' , Data))) * 10000) # weeks recommended Print (TOTAL_NUM, total_recommend, week_recommend) DEF main (url): fan_info,data = get_html_info(url) web_font_relation =get_Font (fan_info) get_encode_font (Data, web_font_relation) "" " main entry " "" IF the __name__ == ' __main__ ' : URL = ' https://book.qidian.com/info/1115277 ' # select a novel main (url)