1.抓包

  

2.代码

  抓取:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#author tom
import requests
from multiprocessing import Queue
from handle_pymongo import mongo
from concurrent.futures import ThreadPoolExecutor class Douguo():
def __init__(self):
self.queue_list=Queue() #因为所有的请求的请求头都一样,所以放在这边处理,其实请求头也可以放在__init__
def handle_request(self,url,data):
headers={
"client":"",
"version":"6920.4",
"device":"SM-G9350",
"sdk":"22,5.1.1",
"imei":"",
"channel":"qqkp",
# "mac":"2c:c3:82:e2:0b:03",
"resolution":"1024*576",
"dpi":"1.19375",
# "android-id":"4014041355524873",
# "pseudo-id":"28075263",
"brand" :"samsung",
"scale" :"1.19375",
"timezone":"",
"language":"zh",
"cns":"",
# "imsi":"460005263415341",
"user-agent":"Mozilla/5.0 (Linux; Android 5.1.1; SM-G9350 Build/LMY48Z) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36",
"reach" :"",
"newbie":"",
"Content-Type":"application/x-www-form-urlencoded; charset=utf-8",
"Accept-Encoding":"gzip, deflate",
# "Cookie":"duid=59758072", #能不带最好不带
"Host":"api.douguo.net",
# "Content":"-Length 68",
"Connection":"keep-alive"
}
response = requests.post(url=url, headers=headers,data=data)
return response #请求食谱首页
def handle_index(self):
url='http://api.douguo.net/recipe/flatcatalogs'
data={
"client":"",
# "_session":"1557318413116861373280750547",
# "v":"1503650468",
"_vs": ""
}
response_index=self.handle_request(url,data)
indext_response_dict=response_index.json()
#遍历这个三级分类
for index_item in indext_response_dict['result']['cs']:
for items in index_item['cs']:
for item in items['cs']:
#每一个小分类
data2={
"client": "",
# "_session": "1557318413116861373280750547",
"keyword":item['name'],
"order": "",
"_vs": ""
}
self.queue_list.put(data2) #请求具体食材的做法
def handle_caipu_list(self,data):
print("当前处理的食材是:",data['keyword'])
#翻页
for i in range(1,11):
caipu_list_url='http://api.douguo.net/recipe/v2/search/{0}/20'.format(str(i*20))
caipu_list_response=self.handle_request(url=caipu_list_url,data=data)
caipu_list_dict=caipu_list_response.json()
#判断是否有数据
if caipu_list_dict['result']['end']==1:
break
for item in caipu_list_dict['result']['list']:
caipu_info={}
caipu_info['shicai'] = data['keyword']
if item['type']==13:
caipu_info['user_name']=item['r']['an']
caipu_info['shicai_id']=item['r']['id']
caipu_info['describe']=item['r']['cookstory'].replace('/n','').replace(' ','')
caipu_info['caipu_name']=item['r']['n']
caipu_info['zuoliao_list']=item['r']['major']
# print(caipu_info)
#获取详情页的内容
detail_url='http://api.douguo.net/recipe/detail/'+str(caipu_info['shicai_id'])
detail_data={
"client": "",
# "_session": "1557318413116861373280750547",
"author_id": "",
"_vs": "",
"_ext":'{"query": {"kw": '+caipu_info['shicai']+', "src": "2803", "idx": "1", "type": "13", "id": '+str(caipu_info['shicai_id'])+'}}'
}
detail_response=self.handle_request(url=detail_url,data=detail_data)
detail_response_dict=detail_response.json()
caipu_info['tips']=detail_response_dict['result']['recipe']['tips']
caipu_info['cook_step']=detail_response_dict['result']['recipe']['cookstep']
print('当前入库的是:',caipu_info['caipu_name'])
mongo.inset_item(caipu_info)
#g过滤掉广告
else:
continue if __name__ == '__main__':
d=Douguo()
d.handle_index()
pool=ThreadPoolExecutor(max_workers=20)
while d.queue_list.qsize()>0:
pool.submit(d.handle_caipu_list,d.queue_list.get())

  存储:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#author tom
import pymongo class Connect_Mongo(object):
def __init__(self):
self.client=pymongo.MongoClient(host='127.0.0.1',port=27017)
self.db=self.client['doukou_meishi'] def inset_item(self,item):
self.collection=self.db['meishi']
self.collection.insert(item) mongo=Connect_Mongo()

app之---豆果美食的更多相关文章

  1. python-python爬取豆果网(菜谱信息)

    #-*- coding = utf-8 -*- #获取豆果网图片 import io from bs4 import BeautifulSoup import requests #爬取菜谱的地址 ur ...

  2. 融云(找到“每个App都有沟通的需求”的细分市场)

    近日,国内著名App驾考宝典和融云达成合作,为应用增加IM功能,实现亿级用户之间聊天.消息一出,IM(即时通讯)领域的大佬,同时也是个上线不到两岁的新生力量,再次引发了行业的关注. 对业内人士而言,即 ...

  3. app界面设计字体规范

    通过对不同类型的app进行总结,总结出app的字体规范. 一.字体选择 1.IOS:苹果ios 9系统开始,系统最新的默认中文字体是:苹方.英文字体是: San Francisco 2.Android ...

  4. App界面设计规范-字体规范

    通过对不同类型的app进行总结,总结出app的字体规范. 一.字体选择 1.IOS:苹果ios 9系统开始,系统最新的默认中文字体是:苹方.英文字体是: San Francisco 2.Android ...

  5. 美食查询手机应用"吃了么":NABC

    一 N(need) 当你在一个陌生的地方游玩,想吃到当地的招牌美食时怎么办? 当你听说有一个很好吃的家常菜,也想自己下厨试试时怎么办?打印出菜谱,还是奔波于厨房和电脑之前? 查询周边美食的功能对于那些 ...

  6. 团队作业(五)-笔记app top5

    在互联网快速发展的情况下,各个行业的软件层出不穷,五花八门.各个行业都有相当多的软件介入其中,在如此多的软件之中,便有了相当激烈的竞争角逐.今天我们十五万的总冠军就着笔记APP行业中位列top 5的软 ...

  7. 微信Web APP应用

    微信Web APP即微信公众账号,对web APP的提供者来说这是一个门槛极低,容易到达数亿真实用户且确保用户黏性的分发平台;对用户来说,这是一种前所未有及其简单的应用使用方式;对腾讯来 说,将形成微 ...

  8. Top Android App使用的组件(应用)

    Top Android App使用的组件   唱吧_462 smack:de.measite.smack:??? ???:org.apache:??? smack:org.jivesoftware.s ...

  9. Scrapy——6 APP抓包—scrapy框架下载图片

    Scrapy——6 怎样进行APP抓包 scrapy框架抓取APP豆果美食数据 怎样用scrapy框架下载图片 怎样用scrapy框架去下载斗鱼APP的图片? Scrapy创建下载图片常见那些问题 怎 ...

随机推荐

  1. GBDT的理解和总结

    2015/11/21 16:29:29 by guhaohit 导语: GBDT是非常有用的机器学习的其中一个算法,目前广泛应用于各个领域中(regression,classification,ran ...

  2. 转:Zabbix 监控sqlserver

    一:Zabbix监控sqlserver 方法一: 1.思路整理 1.在zabbix server上安装Freetds.unixODBC.unixODBC-devel使其能够访问SQL Server数据 ...

  3. hadoop创建两大错误:Bad connection to FS. command aborted. exception和Shutting down NameNode at hadoop

    1.问题目录表: Error代码   failed on connection exception: java.net.ConnectException: Connection refused 3.  ...

  4. JAVA的堆栈和内存、垃圾回收解说

    1.有关java健壮性特点的真相 很多书上都说java健壮性的特点是因为java使用数组代替了c++的指针:c++最令人头痛的问题就是内存问题,java的健壮性使编程人员不用再考虑内存的问题:这种观点 ...

  5. Nginx的四层和七层代理

    理论部分: 所谓四层负载均衡,也就是主要通过报文中的目标地址和端口,再加上负载均衡设备设置的服务器选择方式,决定最终选择的内部服务器,它一般走的是tcp,udp协议    所谓七层负载均衡,也称为“内 ...

  6. HTML5图片预览 放大

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. spring boot 创建定时任务

    @Scheduled默认创建的线程是单线程,任务的执行会受到上一个任务的影响,创建定时任务也比较简单 123456789101112 @Component@Configuration //1.主要用于 ...

  8. Memcached笔记——(二)XMemcached&Spring集成

    今天研究Memcached的Java的Client,使用XMemcached 1.3.5,做个简单的测试,并介绍如何与Spring集成. 相关链接: Memcached笔记--(一)安装&常规 ...

  9. 吴裕雄--天生自然 PHP开发学习:本地PHPSTORM在线连接、编辑、上传文件到虚拟机,并在本地浏览器运行(前提是虚拟机与本机已桥连成功)

  10. python 使用 UTF-8 编码

    题记 一般我喜欢用 utf-8 编码,在 python 怎么使用呢? 使用utf-8 文字 在 python 源码文件中用 utf-8 文字.一般会报错,如下: File "F:\works ...