爬虫--反爬--css反爬---大众点评爬虫
大众点评爬虫分析,,大众点评 的爬虫价格利用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反爬---大众点评爬虫的更多相关文章
- 【Python3爬虫】大众点评爬虫(破解CSS反爬)
本次爬虫的爬取目标是大众点评上的一些店铺的店铺名称.推荐菜和评分信息. 一.页面分析 进入大众点评,然后选择美食(http://www.dianping.com/wuhan/ch10),可以看到一页有 ...
- Node.js大众点评爬虫
大众点评上有很多美食餐馆的信息,正好可以拿来练练手Node.js. 1. API分析 大众点评开放了查询商家信息的API,这里给出了城市与cityid之间的对应关系,链接http://m.api.di ...
- Python爬虫反反爬:CSS反爬加密彻底破解!
刚开始搞爬虫的时候听到有人说爬虫是一场攻坚战,听的时候也没感觉到特别,但是经过了一段时间的练习之后,深以为然,每个网站不一样,每次爬取都是重新开始,所以,爬之前谁都不敢说会有什么结果. 前两天,应几个 ...
- 大众点评评论数据抓取 反爬虫措施有css文字映射和字体库反爬虫
大众点评评论数据抓取 反爬虫措施有css文字映射和字体库反爬虫 大众点评的反爬虫手段有那些: 封ip,封账号,字体库反爬虫,css文字映射,图形滑动验证码 这个图片是滑动验证码,访问频率高的话,会出 ...
- python爬虫实战---爬取大众点评评论
python爬虫实战—爬取大众点评评论(加密字体) 1.首先打开一个店铺找到评论 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经 ...
- Python爬虫入门教程 64-100 反爬教科书级别的网站-汽车之家,字体反爬之二
说说这个网站 汽车之家,反爬神一般的存在,字体反爬的鼻祖网站,这个网站的开发团队,一定擅长前端吧,2019年4月19日开始写这篇博客,不保证这个代码可以存活到月底,希望后来爬虫coder,继续和汽车之 ...
- python爬虫爬取大众点评并导入redis
直接上代码,导入redis的中文编码没有解决,日后解决了会第一时间上代码!新手上路,多多包涵! # -*- coding: utf-8 -*- import re import requests fr ...
- Python 爬取大众点评 50 页数据,最好吃的成都火锅竟是它!
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 胡萝卜酱 PS:如有需要Python学习资料的小伙伴可以加点击下方链 ...
- 用Python爬取大众点评数据,推荐火锅店里最受欢迎的食品
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:有趣的Python PS:如有需要Python学习资料的小伙伴可以加点 ...
随机推荐
- Halcom学习笔记1——Halcon知识点
文件: 1.浏览HDevelop示例程序 2.程序另存在:Ctrl+Shift+S 3.导出:Ctrl+Shift+O X 编辑: 1.快捷键: F3 激活 F4 注销 重复查找:C ...
- 20162322 朱娅霖 作业011 Hash
20162322 2017-2018-1 <程序设计与数据结构>第十一周学习总结 教材学习内容总结 哈希方法 一.定义 哈希:次序--更具体来说是项在集合中的位置--由所保存元素值的某个函 ...
- [leetcode]15. 3Sum三数之和
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find ...
- canvas(三) star- demo
/** * Created by xianrongbin on 2017/3/8. * 本例子使用渐变画出 璀璨星空 */ var dom = document.getElementById('clo ...
- grafana add custom dashboard
grafana-dashboard-json prometheus-operator helm 中的grafana dashboard 扩展的时候,需要转换下载(https://grafana.com ...
- 如何通过RNA-Seq了解转录本的结构
[转载]如何通过RNA-Seq了解转录本的结构 已有 1942 次阅读 2014-12-26 15:22 |个人分类:转录组测序|系统分类:科研笔记|关键词:RNA-Seq,转录组测序,转录本结构| ...
- python 的面相对象编程--对应c++
在python的面相对象编程中,我们常常在class中可以看到a(), _b() , __c(), __d()__这样的函数. 由于我是看廖雪峰老师的教程,廖老师为了简单起见,没有引入太多概念,我 ...
- CSS3美化网页!!
一.span标签:能让某几个文字或者某个词语凸显出来 <p> 今天是11月份的<span>第一天</span>,地铁卡不打折了 ...
- Android 简单布局、控件
布局 线性布局 LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android ...
- IIS7部署网站遇到的问题
1.web.config文件中更改配置项时: 因为 IIS 7 采用了更安全的 web.config 管理机制,默认情况下会锁住配置项不允许更改. 运行命令行 %windir%\system32\ ...