大众点评爬虫分析,,大众点评 的爬虫价格利用css的矢量图偏移,进行加密

只要拦截了css 解析以后再写即可

# -*- coding: utf- -*-
"""
Created on Sat Apr :: @author: Administrator
"""
import re
import requests
from bs4 import BeautifulSoup headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Cookie': 'cy=13; cye=wuxi; _lx_utm=utm_source%3DBaidu%26utm_medium%3Dorganic; _lxsdk_cuid=16a5c669f37c8-00e87b02ef26eb-e323069-1fa400-16a5c669f38c8; _lxsdk=16a5c669f37c8-00e87b02ef26eb-e323069-1fa400-16a5c669f38c8; _hc.v=0ff28a55-7cc0-b228-f700-c5a9a02cf919.1556328391; s_ViewType=10; _lxsdk_s=16a5c669f39-2cc-cf2-eeb%7C%7C64',
'Host': 'www.dianping.com',
'Referer': 'https://www.dianping.com/',
'Upgrade-Insecure-Requests': '',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'
}
#url = 'https://www.dianping.com/search/keyword/13/0_%E4%B8%87%E8%B1%A1%E5%9F%8E' # 万象城
url = 'https://www.dianping.com/search/keyword/13/0_%E4%B8%80%E7%82%B9%E7%82%B9'
tem = requests.get(url, headers = headers)
ls = tem.text
soup = BeautifulSoup(ls, 'lxml')
#//div[@class="shop-list J_shop-list shop-all-list"]
linkes = soup.select('link[type="text/css"]') '''获取svg css链接代码'''
for link in linkes:
tem = link.attrs['href']
if tem.__contains__('svg'):
svg_href = 'https:'+tem
css_html = requests.get(svg_href).text # 获取svg的内容 '''获取标题'''
titles = []
pes = []
title = soup.select('div[class="shop-list J_shop-list shop-all-list"] ul li div[class="tit"] a h4')
for t in title:
titles.append(t.get_text())
'''获取数据url的方法,传入参数为前两个字母'''
def get_svg_url(svg_):
svg_url = "http:" + re.findall('class\^="{}".+(//.+svgtextcss.+\.svg)'.format(svg_),
'\n'.join(css_html.split('}')))[]
return svg_url
'''获取价格'''
comment = soup.select('div[class="shop-list J_shop-list shop-all-list"] ul li div[class="comment"]')
for com in comment:
tem_price = com.select('a')
price = tem_price[].select('b')
svges = tem_price[].select('b svgmtsi')
if price == []:
pes.append(' ')
continue
tem_pri1 = price[] # 价格直接显现的部分
str_pri1 = re.findall('<b>(.*?)</b>', str(tem_pri1))[] # 去除b
pri1=re.sub(r'<svgmtsi class=".*"></svgmtsi>',' ',str_pri1)
# pri1 = tem_pri1.get_text()
# print(pri1)
pri2 = ''
for svg in svges:
tem_svg = svg.attrs['class'][] # svg的属性
xy_loc = re.findall('{}{{background:(.*?);}}'.format(tem_svg),css_html)[].split(' ') #正则将其的坐标提取处理,注意{{}}
svg_url = get_svg_url(tem_svg[:])
thr = requests.get(svg_url).text
y = abs(float(xy_loc[].replace('px', ''))) # 坐标的y轴
sop = BeautifulSoup(thr, 'lxml')
text = sop.select('text')
for te in text: # 判断密文在第几行并找出密文
index = float(te.attrs['y'])
if y <= index:
miwen = te.get_text()
break
'''解密x,判断其位置'''
x = float(xy_loc[].replace('px', '')) # 坐标的y轴
ind = int((x+)/(-))
tem_pri = list(miwen)[ind]
pri2 = pri2+tem_pri
# print(pri1.replace(' ',pri2))
# print(pri1, pri2)
pes.append(pri1.replace(' ',pri2))
# print(tem_pri)
# pri2 = svges
# price = pri1.replace(' ',pri2)
# print(pri1, pri2) for i,j in zip(titles,pes):
print(i,j)

爬虫--反爬--css反爬---大众点评爬虫的更多相关文章

  1. 【Python3爬虫】大众点评爬虫(破解CSS反爬)

    本次爬虫的爬取目标是大众点评上的一些店铺的店铺名称.推荐菜和评分信息. 一.页面分析 进入大众点评,然后选择美食(http://www.dianping.com/wuhan/ch10),可以看到一页有 ...

  2. Node.js大众点评爬虫

    大众点评上有很多美食餐馆的信息,正好可以拿来练练手Node.js. 1. API分析 大众点评开放了查询商家信息的API,这里给出了城市与cityid之间的对应关系,链接http://m.api.di ...

  3. Python爬虫反反爬:CSS反爬加密彻底破解!

    刚开始搞爬虫的时候听到有人说爬虫是一场攻坚战,听的时候也没感觉到特别,但是经过了一段时间的练习之后,深以为然,每个网站不一样,每次爬取都是重新开始,所以,爬之前谁都不敢说会有什么结果. 前两天,应几个 ...

  4. 大众点评评论数据抓取 反爬虫措施有css文字映射和字体库反爬虫

    大众点评评论数据抓取  反爬虫措施有css文字映射和字体库反爬虫 大众点评的反爬虫手段有那些: 封ip,封账号,字体库反爬虫,css文字映射,图形滑动验证码 这个图片是滑动验证码,访问频率高的话,会出 ...

  5. python爬虫实战---爬取大众点评评论

    python爬虫实战—爬取大众点评评论(加密字体) 1.首先打开一个店铺找到评论 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经 ...

  6. Python爬虫入门教程 64-100 反爬教科书级别的网站-汽车之家,字体反爬之二

    说说这个网站 汽车之家,反爬神一般的存在,字体反爬的鼻祖网站,这个网站的开发团队,一定擅长前端吧,2019年4月19日开始写这篇博客,不保证这个代码可以存活到月底,希望后来爬虫coder,继续和汽车之 ...

  7. python爬虫爬取大众点评并导入redis

    直接上代码,导入redis的中文编码没有解决,日后解决了会第一时间上代码!新手上路,多多包涵! # -*- coding: utf-8 -*- import re import requests fr ...

  8. Python 爬取大众点评 50 页数据,最好吃的成都火锅竟是它!

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 胡萝卜酱 PS:如有需要Python学习资料的小伙伴可以加点击下方链 ...

  9. 用Python爬取大众点评数据,推荐火锅店里最受欢迎的食品

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:有趣的Python PS:如有需要Python学习资料的小伙伴可以加点 ...

随机推荐

  1. <转>ajax 同步异步问题

    原文:https://blog.csdn.net/wxr15732623310/article/details/76387787 看似简单明白的问题说起来却迷迷糊糊,完全没有逻辑,说不到重点上,再来整 ...

  2. 关于ie6块元素行内元素转换

    1.inline元素的display属性设置为inline-block时,所有的浏览器都支持: 2.block元素的display属性设置为inline-block时,IE6/IE7浏览器是不支持的: ...

  3. C++中绝对值的运算

    首先,输入-42333380005结果取出来的绝对值却是616292955. 开始我以为是long型的取值范围有问题,就把long型全部改为long long型的了,结果还是一样,就觉得绝对值这个函数 ...

  4. 322. Coin Change选取最少的硬币凑整-背包问题变形

    [抄题]: You are given coins of different denominations and a total amount of money amount. Write a fun ...

  5. Centos Firefox中文乱码

    解决CentOS Firefox 中文乱码问题,执行以下命令 Centos 6 # yum -y groupinstall chinese-support 重启电脑即可. Centos 7 yum - ...

  6. redis使用规范文档 20170522版

    运维redis很久了,一直是口头给rd说各种要求,尝试把这些规范总结成文档 摘选一些可能比较通用的规则如下: 强制:所有的key设置过期时间(最长可设置过期时间10天,如有特殊要求,联系dba说明原因 ...

  7. 【ElasticSearch】 安装

    Elasticsearch简介 Elasticsearch 是一个开源的分布式 RESTful 搜索和分析引擎,能够解决越来越多不同的应用场景 官网地址:https://www.elastic.co ...

  8. Scrum冲刺阶段2

    成员今日完成的任务 人员 任务 何承华 后端设计 陈宇 后端设计 丁培辉 后端设计 温志铭 主页面的设计 杨宇潇 主页面的设计 张主强 服务器构建 成员遇到的问题 人员 问题 何承华 暂无 陈宇 暂无 ...

  9. Mybatis的针对于同一个有自己父类或子类的递归查询 (如商品分类)

    1.pojo代码 private Integer categoryId; private Integer superId; private String name; private Byte leve ...

  10. mysql data type <----> java data type (数值)

    https://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html +----------------------------+---- ...