码迷,mamicode.com
首页 > 移动开发 > 详细

6.简单提取小红书app数据保存txt-2

时间:2018-11-02 12:57:14      阅读:1585      评论:0      收藏:0      [点我收藏+]

标签:header   headers   sign   roi   cos   json   coding   ccf   教程   

对页面信息进行简单抓取:

需要注意的问题 :
auth-sign 和 auth 都是有一定的时效性,还有url原url是https这里要改为http请求。
这参数的问题需要通过mitmdump去获取请求的具体参数并将之取出,不用手动去截获分析http请求和响应,写好请求和相应的处理逻辑,通过python实现二次操作。

后期通过appium模拟人为操作去滑动请求刷新界面,得到相应再做处理。

import requests

def main():
    headers = {
    "charset":"utf-8",
    "Accept-Encoding":"gzip",
    "referer":"https://servicewechat.com/wxffc08ac7df482a27/117/page-frame.html",
    "authorization":"5bda7657a4ce660001f7eed8",
    "auth":"eyJoYXNoIjoibWQ0IiwiYWxnIjoiSFMyNTYiLCJ0eXAiOiJKV1QifQ.eyJzaWQiOiI0M2RkNGY2YS01NTk1LTRjNGEtYTkyMi05ODEzNjdiMTlmMTEiLCJleHBpcmUiOjE1NDExMzAyNjJ9.9AC8VBcXiBG48vHa-LLgVEWOnloTdQvNWzYAyvqGnMA",
    "content-type":"application/json",
    "auth-sign":"c475525b214bb5d9ae431ac029cb9b50",
    "User-Agent":"Mozilla/5.0 (Linux; Android 7.1.2; MI 5X Build/N2G47H; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/64.0.3282.137 Mobile Safari/537.36 MicroMessenger/6.7.3.1360(0x26070336) NetType/WIFI Language/zh_CN Process/appbrand2",
    "Host":"www.xiaohongshu.com",
    "Connection":"Keep-Alive",
    }
    # url = "http://www.xiaohongshu.com/sapi/wx_mp_api/sns/v1/homefeed?oid=homefeed.cosmetics_v2&cursor_score=&sid=session.1540996623416187718"
    url = "http://www.xiaohongshu.com/sapi/wx_mp_api/sns/v1/homefeed?oid=homefeed.cosmetics_v2&cursor_score=1541067389.9550&sid=session.1540996623416187718"


    datas = requests.get(url= url, headers=headers ).json()
    data = datas[data]
    # print(data)
    for i in data:
        print(i)
        # print(i[‘title‘])
        # print(i[‘share_link‘])
        title = 标题:  + i[mini_program_info][share_title]
        print(title)
        link_url = 链接:  + i[share_link]
        print(link_url)
        b_picture = 封面图片: + i[mini_program_info][thumb]
        print(b_picture)
        type = 类型:  + i[type]
        print(type)
        level = 级别:  + str(i[level])
        print(level)
        h_picture = 用户头像:  + i[user][images]
        print(h_picture)
        username = 用户名:  + i[user][nickname]
        print(username)
        user_id = userid:  + i[user][userid]
        print(user_id)
        zan = 喜欢点心:  + str(i[likes])
        print(zan)

        # 以追加的方式及打开一个文件,文件指针放在文件结尾,追加读写!
        with open(text, a, encoding=utf-8)as f:
            f.write(\n.join([title,link_url,b_picture,type,level,h_picture,username,user_id,zan]))
            f.write(\n + = * 100 + \n)
if __name__ == "__main__":
    main()

 

保存本地
技术分享图片

 

 

字段信息:
标题: 王者荣耀——貂蝉~仲夏夜之梦 游戏角色貂蝉皮肤印象妆容 主色
链接: https://www.xiaohongshu.com/discovery/item/5bc0b2bf910cf646cc1087aa
封面图片: http://ci.xiaohongshu.com/161f03cb-0cf6-355f-b178-712a928a7720?imageView2/2/w/540/format/jpg
类型: normal
级别: 4
用户头像: https://img.xiaohongshu.com/avatar/5bb1047b0fd0590001997f83.jpg@80w_80h_90q_1e_1c_1x.jpg
用户名: zanleo
userid: 582c5f8982ec393b5ec866ba
喜欢点心: 233
====================================================================================================
标题: ??仲夏夜之紫妆 | HUDA beauty 沙漠黄昏教程
链接: https://www.xiaohongshu.com/discovery/item/5bc9e121672e144fac0d3438
封面图片: http://ci.xiaohongshu.com/29b82aa1-ad20-355c-9d42-396ddf52e5d6?imageView2/2/w/540/format/jpg
类型: normal
级别: 2
用户头像: https://img.xiaohongshu.com/avatar/5a296015d2c8a51d5734be82.jpg@80w_80h_90q_1e_1c_1x.jpg
用户名: Miya杨奶奶_
userid: 558b9f43a75c956c2accf4cf
喜欢点心: 211
====================================================================================================
标题: 6款热门平价粉底上脸测评???? 到底该选哪款? 平价粉底到
链接: https://www.xiaohongshu.com/discovery/item/5bd1ab2a07ef1c2e707bf66c
封面图片: http://ci.xiaohongshu.com/7d86d4bc-1170-524b-8566-2a7ea4e37843?imageView2/2/w/540/format/jpg
类型: video
级别: 4
用户头像: https://img.xiaohongshu.com/avatar/5b20ca00b46c5d4130aad5f9.jpg@80w_80h_90q_1e_1c_1x.jpg
用户名: 喵格singherC
userid: 5aa65f6411be10488ded22ed
喜欢点心: 945
====================================================================================================
标题: 万圣节妆容??超简单|3步搞定星空版的zipper face
链接: https://www.xiaohongshu.com/discovery/item/5bd6882907ef1c7693a1b241
封面图片: http://ci.xiaohongshu.com/7ccd594d-e525-502c-b9bb-4c430158af3c?imageView2/2/w/540/format/jpg
类型: normal
级别: 2
用户头像: https://img.xiaohongshu.com/avatar/5ab3bc0d14de410bdfa82234.jpg@80w_80h_90q_1e_1c_1x.jpg
用户名: 达宝Linda
userid: 5a9e51c2e8ac2b2b796a7b58
喜欢点心: 24
====================================================================================================
标题: 傻瓜式眼线画法??简单三步画出流畅眼线 最近南南收到很多宝宝
链接: https://www.xiaohongshu.com/discovery/item/5bcd2635910cf646df155c0d
封面图片: http://ci.xiaohongshu.com/9d8408ff-0518-5051-93cc-d0f8e8b46ba8?imageView2/2/w/540/format/jpg
类型: video
级别: 4
用户头像: https://img.xiaohongshu.com/avatar/5aba0b9ab46c5d273ecf8e9d.jpg@80w_80h_90q_1e_1c_1x.jpg
用户名: 一枝南南
userid: 5604f1e6e4b1cf3ec7c681aa
喜欢点心: 379
====================================================================================================
标题: ??万圣节妆容| 受伤小精灵妆 不恐怖 仙仙哒? - 万圣节
链接: https://www.xiaohongshu.com/discovery/item/5bd0e707910cf646de1ea5c4
封面图片: http://ci.xiaohongshu.com/cada288c-f792-5d6c-a9c0-da3ada8f7dc9?imageView2/2/w/540/format/jpg
类型: normal
级别: 2
用户头像: https://img.xiaohongshu.com/avatar/5b8a768e9042e3000127ee7c.jpg@80w_80h_90q_1e_1c_1x.jpg
用户名: 原口元子
userid: 584279446a6a697c18b0fd20
喜欢点心: 305
====================================================================================================
标题: 和我一起过万圣节??暗黑系御姐妆容【视频教程
链接: https://www.xiaohongshu.com/discovery/item/5bd6c20b910cf63164681086
封面图片: http://ci.xiaohongshu.com/c1e67a16-ba72-5095-a205-5372d5ffc4b2?imageView2/2/w/540/format/jpg
类型: video
级别: 2
用户头像: https://img.xiaohongshu.com/avatar/5b9bb566e277db00012cae1c.jpg@80w_80h_90q_1e_1c_1x.jpg
用户名: 球大王
userid: 55e96f24a75c950acd3358b8
喜欢点心: 119
====================================================================================================
标题: 90%的女生都不知道的鼻影正确画法
链接: https://www.xiaohongshu.com/discovery/item/5bd3ce20672e143bd2c40c98
封面图片: http://ci.xiaohongshu.com/8e67c937-12d7-5f90-a905-2211fa40c620?imageView2/2/w/540/format/jpg
类型: video
级别: 2
用户头像: https://img.xiaohongshu.com/avatar/5b3de03ad2c8a52d01693211.jpg@80w_80h_90q_1e_1c_1x.jpg
用户名: 爱美妆的雪禾子
userid: 5b3de01911be10724c823add
喜欢点心: 140
====================================================================================================
标题: @赵奕欢Chloe 发了一篇超赞的笔记,快点来看!
链接: https://www.xiaohongshu.com/discovery/item/5bc55241910cf646d416c55a
封面图片: http://ci.xiaohongshu.com/172c29bd-0ba2-5753-bdce-e4f1d98bde67?imageView2/2/w/540/format/jpg
类型: video
级别: 4
用户头像: https://img.xiaohongshu.com/avatar/5ac38c99d2c8a5130c1e4f7a.jpg@80w_80h_90q_1e_1c_1x.jpg
用户名: 赵奕欢Chloe
userid: 5aa12b5311be107df912efb4
喜欢点心: 2557
====================================================================================================
标题: 黄黑皮 涂了也显白的豆沙色! 最滋润的口红 阿玛尼唇釉试色
链接: https://www.xiaohongshu.com/discovery/item/5bc71ffa910cf646d813008d
封面图片: http://ci.xiaohongshu.com/c153caab-44b8-5121-9e49-abc2e7334ae9?imageView2/2/w/540/format/jpg
类型: video
级别: 2
用户头像: https://img.xiaohongshu.com/avatar/5ba395e0e582ff0001888aac.jpg@80w_80h_90q_1e_1c_1x.jpg
用户名: 认真少女_颜九
userid: 5a52d211e8ac2b78a241269e
喜欢点心: 4926
====================================================================================================
 

 

6.简单提取小红书app数据保存txt-2

标签:header   headers   sign   roi   cos   json   coding   ccf   教程   

原文地址:https://www.cnblogs.com/lvjing/p/9895434.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!