大众点评爬虫分析,,大众点评 的爬虫价格利用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. 初学c# -- 学习笔记 小结

    学了到了好些东西, 做了一些练习. 一.C# winform Socket 1.程序主要部分只是用了 Panel.Picturebox.Label.RicheditBox四个组件,滚动条.编辑框什么的 ...

  2. Linux LVM磁盘管理

    几个概念: PV:物理卷,指LVM的基本逻辑卷,包含LVM的基本参数,如/dev/sdb1等. VG:卷组,类似于非LVM的硬盘,由多个PV组成. LV:逻辑卷,类似于非LVM硬盘中的分区. PE:物 ...

  3. MAC book 无法删除普通用户的解决办法

    1来自苹果官网 macOS Sierra: 删除用户或群组 如果您是管理员,当您不想再让某些用户访问 Mac 时,可以删除他们.您也可以删除不想要的群组. 删除用户时,您可以存储该用户的个人文件夹(包 ...

  4. js+正则+单双引号问题

    在处理用js动态添加表格时,表格中有正则表达式,其单双引号问题导致的添加表格不成功,和正则失效问题 <script type="text/javascript"> va ...

  5. 663. Equal Tree Partition 能否把树均分为求和相等的两半

    [抄题]: Given a binary tree with n nodes, your task is to check if it's possible to partition the tree ...

  6. Java比较两个时间的前后

    public static int compare_date(String DATE1, String DATE2) { DateFormat df = new SimpleDateFormat(&q ...

  7. [leetcode]34.Find First and Last Position of Element in Sorted Array找区间

    Given an array of integers nums sorted in ascending order, find the starting and ending position of ...

  8. python基础 (编码进阶,文件操作和深浅copy)

    1.编码的进阶 字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码. 即先将其他编码的字符串解码(decode)成unicode,再从uni ...

  9. python_paramiko

    目录: paramiko模块介绍 paramiko模块安装 paramiko模块使用 一.paramiko模块介绍 paramiko是一个用于做远程控制的模块,使用该模块可以对远程服务器进行命令或文件 ...

  10. [C#.net]ListBox对Item进行重绘,设置背景色和前景色

    别的不多说了,上代码,直接看 首先设置这行,或者属性窗口设置,这样才可以启动手动绘制,参数有三个 Normal: 自动绘制 OwnerDrawFixed:手动绘制,但间距相同 OwnerDrawVar ...