对页面信息进行简单抓取: 需要注意的问题 :
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/[email protected]_80h_90q_1e_1c_1x.jpg用户名: zanleouserid: 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/[email protected]_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/[email protected]_80h_90q_1e_1c_1x.jpg用户名: 喵格singherCuserid: 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/[email protected]_80h_90q_1e_1c_1x.jpg用户名: 达宝Lindauserid: 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/[email protected]_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/[email protected]_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/[email protected]_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/[email protected]_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/[email protected]_80h_90q_1e_1c_1x.jpg用户名: 赵奕欢Chloeuserid: 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/[email protected]_80h_90q_1e_1c_1x.jpg用户名: 认真少女_颜九userid: 5a52d211e8ac2b78a241269e喜欢点心: 4926====================================================================================================
原文地址:https://www.cnblogs.com/lvjing/p/9895434.html
时间: 2024-10-16 06:17:03