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. [LC] 11. Container With Most Water

    Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...

  2. java中Redis5大基本类型的用法

    存储格式 基本用法 通过Jedis(封装了redis的Java客户端)对redis进行操作. Jedis工具类 public class JedisPoolUtil { private static ...

  3. (转)假如没有OI By Vani

    假如没有OI                                                                                               ...

  4. 未释放资源的教训,开发MongoDB连接一定要关闭连接

    废不少工夫将数据存储,全部迁移至mongodb,未作大量改动则是主因. 但遇到奇怪的现象. 程序跑起不久后,mongodb即假死,另起客户端想登陆mongodb都不成. 要重启mongodb服务器才好 ...

  5. 从Surface 3发布 看微软快速转向的根由

    3发布 看微软快速转向的根由" title="从Surface 3发布 看微软快速转向的根由"> 平地一声惊雷起,微软突然送惊喜!在毫无征兆的情况下,微软突然发布一 ...

  6. linux下载文件到本地_把linux服务器的文件下到本地windows

    tar -cvf script.tar scriptsz script.tar 文件夹先要打包,并且要指定打包的名字. 具体:  sz/rz命令:  一般来说,linux服务器大多是通过ssh来进行远 ...

  7. Java JDBC调用inout类型参数的存储过程

    存储过程参数类型:in.out.inout,in:输入类型,out:输出类型,inout:既可输入,也可以输出. 一.JDBC调用inout类型参数的存储过程,并且获得返回值 Class.forNam ...

  8. 阿里云vpc网络SNAT实现内网实例通外网

    需求场景: 因费用和安全考虑,内网部分机器没有分配公网IP,没绑定弹性公网IP,没有购买NAT服务,但是内网机器需要访问外网部分资源,如发送邮件. 操作步骤如下: 1.查看外网上的转发功能的开启没开启 ...

  9. 机器学习的盛宴:NIPS 2015

    作者:微软亚洲研究院实习生:林添 冰雪王国的浪漫 机器学习的盛宴 NIPS(Advances in Neural Information Processing Systems,神经信息处理系统进展大会 ...

  10. 使用powerdesigner进行数据库设计

    powerdesigner安装破解文件:链接:https://pan.baidu.com/s/1oKAdUqTKElQ9d86FV-SDTQ 密码:l4y5 基本操作参考:1.PowerDesigne ...