欢迎来到电脑知识学习网,专业的电脑知识大全学习平台!

手机版

win10系统字体还原-(win10字体还原出厂设置)

电脑故障 发布时间:2022-12-16 17:48:27
(win10字体还原出厂设置)

本文为抓取大众点评数据下篇,主要介绍抓取数据的python实现(含源码)。

一.抓取数据思路1.请求页面源代码,数据解析提取出css

数据提取使用方式为xpath

2.请求css网址,数据解析提取出密码本

数据提取方式为正则表达式

3.下载密码本,获取字体编码与文字间的映射表

下载保存文件

将生成字体编码与文字的映射表写为函数

其中,需要安装一个库(FontTools)用以读取woff文件,将读取的unicode编码值(将耆那三个字母uni变为&#x)与文本内容对应组成键值对,最后形成字典供后续还原数据使用。

4.4.请求网址,数据解析提取加密的数据,通过密码本还原数据

因为数字1在大众点评网没有加密,因此需要把数字“1”与加密数据分开,然后还原加密数据,再将他们按顺序拼在一起。

5.下载还原后的数据

利用pandas库下载数据保存为excel文件

二.python源代码

import requestsfrom lxml import etreeimport refrom fontTools.ttLib import TTFontimport pandasurl = 'https://www.dianping.com/beijing/ch10/g34303'headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.35'}resp = requests.get(url,headers=headers).texttree = etree.HTML(resp)css_url_text = tree.xpath("/html/head/link[9]/@href")[0]#print(css_url_text,type(css_url_text))css_url = 'https:' + css_url_textresp_css = requests.get(css_url)obj = re.compile(",url\(\"(.*?)\"\);}",re.S) woff_url = 'https:' + obj.findall(resp_css.text)[0]with open(r'ziti.woff',mode='wb') as f: f.write(requests.get(woff_url).content)#生成字体编码与文字的映射表def get_font_list(): font = TTFont('ziti.woff') #读取woff文件 font_names = font.getGlyphOrder() texts = [ '', '', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '店', '中', '美', '家', '馆', '小', '车', '大', '市', '公', '酒', '行', '国', '品', '发', '电', '金', '心', '业', '商', '司', '超', '生', '装', '园', '场', '食', '有', '新', '限', '天', '面', '工', '服', '海', '华', '水', '房', '饰', '城', '乐', '汽', '香', '部', '利', '子', '老', '艺', '花', '专', '东', '肉', '菜', '学', '福', '饭', '人', '百', '餐', '茶', '务', '通', '味', '所', '山', '区', '门', '药', '银', '农', '龙', '停', '尚', '安', '广', '鑫', '一', '容', '动', '南', '具', '源', '兴', '鲜', '记', '时', '机', '烤', '文', '康', '信', '果', '阳', '理', '锅', '宝', '达', '地', '儿', '衣', '特', '产', '西', '批', '坊', '州', '牛', '佳', '化', '五', '米', '修', '爱', '北', '养', '卖', '建', '材', '三', '会', '鸡', '室', '红', '站', '德', '王', '光', '名', '丽', '油', '院', '堂', '烧', '江', '社', '合', '星', '货', '型', '村', '自', '科', '快', '便', '日', '民', '营', '和', '活', '童', '明', '器电脑9;, '烟', '育', '宾', '精', '屋', '经', '居', '庄', '石', '顺', '林', '尔', '县', '手', '厅', '销', '用', '好', '客', '火', '雅', '盛', '体', '旅', '之', '鞋', '辣', '作', '粉', '包', '楼', '校', '鱼', '平', '彩', '上', '吧', '保', '永', '万', '物', '教', '吃', '设', '医', '正', '造', '丰', '健', '点', '汤', '网', '庆', '技', '斯', '洗', '料', '配', '汇', '木', '缘'电脑, '加', '麻', '联', '卫', '川', '泰', '色', '世', '方', '寓', '风', '幼', '羊', '烫', '来', '高', '厂', '兰', '阿', '贝', '皮', '全', '女', '拉', '成', '云', '维', '贸', '道', '术', '运', '都', '口', '博', '河', '瑞', '宏', '京', '际', '路', '祥', '青', '镇', '厨', '培', '力', '惠', '连', '马', '鸿', '钢', '训', '影', '甲', '助', '窗', '布', '富', '牌', '头', '四', '多', '妆', '吉', '苑'电脑;, '沙', '恒', '隆', '春', '干', '饼', '氏', '里', '二', '管', '诚', '制', '售', '嘉', '长', '轩', '杂', '副', '清', '计', '黄', '讯', '太', '鸭', '号', '街', '交', '与', '叉', '附', '近', '层', '旁', '对', '巷', '栋', '环', '省', '桥', '湖', '段', '乡', '厦', '府', '铺', '内', '侧', '元', '购', '前', '幢', '滨', '处', '向', '座', '下', '県', '凤', '港', '开', '关', '景', '泉', '塘', '放', '昌', '线', '湾', '政', '步', '宁', '解', '白', '田', '町', '溪', '十', '八', '古', '双', '胜', '本', '单', '同', '九', '迎', '第', '台', '玉', '锦', '底', '后', '七', '斜', '期', '武', '岭', '松', '角', '纪', '朝', '峰', '六', '振', '珠', '局', '岗', '洲', '横', '边', '济', '井', '办', '汉', '代', '临', '弄', '团', '外', '塔', '杨', '铁', '浦', '字', '年', '岛', '陵', '原', '梅', '进', '荣', '友', '虹', '央', '桂', '沿', '事', '津', '凯', '莲', '丁', '秀', '柳', '集', '紫', '旗', '张', '谷', '的', '是', '不', '了', '很', '还', '个', '也', '这', '我', '就', '在', '以', '可', '到', '错', '没', '去', '过', '感', '次', '要', '比', '觉', '看', '得', '说', '常', '真', '们', '但', '最', '喜', '哈', '么', '别', '位', '能', '较', '境', '非', '为', '欢', '然', '他', '挺', '着', '价', '那', '意', '种', '想', '出', '员', '两', '推', '做', '排', '实', '分', '间', '甜', '度', '起', '满', '给', '热', '完', '格', '荐', '喝', '等', '其', '再', '几', '只', '现', '朋', '候', '样', '直', '而', '买', '于', '般', '豆', '量', '选', '奶', '打', '每', '评', '少', '算', '又', '因', '情', '找', '些', '份', '置', '适', '什', '蛋', '师', '气', '你', '姐', '棒', '试', '总', '定', '啊', '足', '级', '整', '带', '虾', '如', '态', '且', '尝', '主', '话', '强', '当', '更', '板', '知', '己', '无', '酸', '让', '入', '啦', '式', '笑', '赞', '片', '酱', '差', '像', '提', '队', '走', '嫩', '才', '刚', '午', '接', '重', '串', '回', '晚', '微', '周', '值', '费', '性', '桌', '拍', '跟', '块', '调', '糕' ] #文本数据,按上面的编码数据顺序排列 font_list_first = {} for index,value in enumerate(texts): font_list_first[font_names[index]] = value font_list_end = {} for i,j in font_list_first.items(): if i.startswith('uni'): key = i.replace('uni','&#x') font_list_end[key] = j else: font_list_end[i] = j return font_list_endshop_lists = tree.xpath('//*[@id="shop-all-list"]')for i in shop_lists: shop_name = i.xpath('./ul//h4/text()')#print(shop_name)font_list = get_font_list() def get_review_num(resp,font_list): obj_review = re.compile('class="review-num".*?<b>(?P<text>.*?)</b>',re.S) text_review_1 = obj_review.finditer(resp) list_review_1 = [] list_review = [] for i in text_review_1: list_review_1.append(i.group('text').replace('<svgmtsi class="shopNum">','').replace('</svgmtsi>','')) for i in range(len(list_review_1)): list_review_1[i] = list_review_1[i].split(';') for j in range(len(list_review_1[i])): if list_review_1[i][j].startswith('1') and list_review_1[i][j].startswith('11'): list_review_1[i][j] = str(font_list[list_review_1[i][j][2:]]) list_review_1[i].insert(j,str(11)) elif list_review_1[i][j].startswith('1') and (not list_review_1[i][j].startswith('11')) and (not list_review_1[i][j] == str(1)): list_review_1[i][j] = str(font_list[list_review_1[i][j][1:]]) list_review_1[i].insert(j, str(1)) elif list_review_1[i][j] == str(1): continue elif list_review_1[i][j].startswith('&'): list_review_1[i][j] = str(font_list[list_review_1[i][j]]) else: continue #print(list_review_1) for i in list_review_1: list_review.append(''.join(i)) return list_reviewlist_review = get_review_num(resp,font_list)#print(list_review)def get_average_price(resp,font_list): obj_price = re.compile(r'<b>¥(.*?)</b>',re.S) text_price = obj_price.findall(resp) list_price = [] for i in range(len(text_price)): text_price[i] = text_price[i].replace('<svgmtsi class="shopNum">','').replace('</svgmtsi>','') for i in range(len(text_price)): text_price[i] = text_price[i].split(';') for j in range(len(text_price[i])): if text_price[i][j].startswith('1') and text_price[i][j].startswith('11'): text_price[i][j] = str(font_list[text_price[i][j][2:]]) text_price[i].insert(j,str(11)) elif text_price[i][j].startswith('1') and (not text_price[i][j].startswith('11')) and (not text_price[i][j] == str(1)): text_price[i][j] = str(font_list[text_price[i][j][1:]]) text_price[i].insert(j, str(1)) elif text_price[i][j] == str(1): continue elif text_price[i][j].startswith('&'): text_price[i][j] = str(font_list[text_price[i][j]]) else: continue for i in text_price: list_price.append(''.join(i)) #print(list_price) return list_priceaverage_price = get_average_price(resp,font_list)#print(average_price)#下载数据data = { '店铺名': shop_name, '评论数': list_review, '人均价': average_price}df = pandas.DataFrame(data)df.to_excel('大众点评.xlsx',index=False)三.总结

本文带来大众点评数据的python爬虫实现,当然在还原数据部分我使用的方法/代码有点繁琐,大家有好的方法可以在评论区交流学习。另外,本文抓取的只是大众点评的极小部分数据,主要帮助大家了解学习字体加密,大家可以互相讨论学习。

#头条创作挑战赛#


电脑
责任编辑:电脑知识学习网

电脑故障