前言
嗨喽~大家好呀,这里是魔王呐 !
让我们一起来学习吧~
开发环境:
- Python 3.8
- Pycharm
模块使用:
第三方模块 需要安装 在cmd里面 进行 pip install requests / parsel
- requests
如何安装python第三方模块:
- win + R 输入 cmd 点击确定, 输入安装命令 pip install 模块名 (pip install requests) 回车
- 在pycharm中点击Terminal(终端) 输入安装命令
代码
获取源码链接点击
import requests headers = { 'cookie': 'csrftoken=1fbccfe7be3950546f7138f25091d746; _routing_id="69be489d-566e-4ba3-9b0c-0101e5cc8a2e"; sessionFunnelEventLogged=1; g_state={"i_l":0}; _auth=1; _pinterest_sess=TWc9PSZEQ1FEMWt1S05WRTZJa1U1eFh6ZlpEdnc5OXRqdUlLZE9VemlNT3pZWEgwOFM3VDVNZkowcHVFSXRtai9LWWNXbjF3c3dPL05aYUNaeFc4RlpscTVJaVFQbUVaUllCKzNCTGY2OTFGWUdYZlJ5cHUwRUJxREJENnVCdlFpMWVYU3hiSUdaZElkRzBndEZ4VHB3VC9KK09Qd0RqbWYrcjRBbHZ4L2RGWW51NjdJMnBYQlhxV2RMdFZpNk1iQ1BwblNJWnVxQmNhclM4NFJkalpMU3hKWEsvUUlLdS8yMVNlK3JTUkZROEVtaGZkU3p6bElHd3JVdkJldUNTN1RISy9Qc3kyZmN5cmZBVk8veFZVNFVoSDZ4dkliK0NWSml0Z2ZhWU5mTUNMK0Jna0NMc3AwdkZZOXhHVC9qVVc0T05OTG1iUE5va09OY2xBMERBUDgvNXQzdnFyVVBVVnczNlhENnJjK3NYdFllZ3Y1bUhyaVBtcW8zS29RZHI0dDdvQUJUdzF0UU1idjNPb2w3UUZsaUpNcitXaU94c0ZzWldwdXBZTjJIcHVIb1Y5NmtmbUVIa09vOVFkKzRnMXZSZ2lFM0dZaktNSUtBNzdHQVMvVEgxaWhWcjJEc3FjMUF6QzdWU2tCNzVmYS9VNTVrV1FqeE5WbHV3QzRhRTlaZ0drVjNuVUwvSUNvc3hMUlNSZ2RwMzI4VUpoN0JndXN4QUNMR2lVa2xXRklJME9uNHBwd3VvMzM5a0ZjbHRXZVVobXhxUTdtdDdrR3dyKzh1dWlITHRISlhuM0U2RnZRLzhzS2lXYUxCbWJxMlRlYk5ZNnNQK2o1WlhIWVNTQzJOdk5Qc0wwdllCMWhHQ3FmOTJ4aFRjWkh5ZUJvYk0xS1J0Vy80UUpWQXF4bGdVOElCRm1lM2NBNVB5ejlNY0ZTTE9Jc25GM09XNW9jekIyd1NRMFJ2Y1NhU2kySDJFRGI5SmIzWWFiK01DVEN5ZmRtdlJzb0p5Y2NxeTdsTFE0MnlPc0RlT1hlRDg4RzI0Qi9kREJGMlJmZHBnPT0mSlFoTnZSdXVhQXo1UWt0UmVxRGZxYWtlWDlJPQ==; _b="AWhINcS3C8VBV4G03jvnkIaZom1KWxg8XVIgP4mExnEZvkkYv/AuTCOEObC+45sj5iQ="; cm_sub=none',
![](https://www.acfun.cn/imageProxy?url=https://upload-images.jianshu.io/upload_images/13117506-bcccc76e5e045c88.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36' } def get_next(bookmark): url = 'https://www..com/resource/UserHomefeedResource/get/?source_url:/&{"options":{"field_set_key":"hf_grid","in_nux":false,"in_news_hub":false,"prependPartner":false,"static_feed":false,"bookmarks":["'+bookmark+'"],"no_fetch_context_on_resource":false},"context":{}}&_=1664260179856'
因链接太长,CSDN又不能出现网站链接
所以上面得代码我就把它删了,大家可以按照下面得图片把它添加一下
![](https://www.acfun.cn/imageProxy?url=https://upload-images.jianshu.io/upload_images/13117506-23b77bb36ad283ee.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
json_data = requests.get(url, headers=headers).json() bookmark = json_data['resource_response']['bookmark'] for data in json_data['resource_response']['data']: img_url = data['images']['orig']['url'] print(img_url) img_name = img_url.split('/')[-1] img_data = requests.get(img_url).content with open(f'img/{img_name}', mode='wb') as f: f.write(img_data) get_next(bookmark) get_next('Y2JVSG80T1ZFd1JrSlJhMFpDVVZWR1FsRlhPVUpSVjJSQ1VWVkdXbFJxYkhaa2EwWlVVVEJHUWxKRlJrSlJWVVpJVVZjNVFsRnJaM1pNZVRoMlRIazRka3d5ZUZWUk1FWkNVakJHUWxGVlJraFZXRTVDVVc1a1FsRlZSa0pOU0doUFlXeHJkMVJYY0Zwa01ERlZXVE53VUZKRmF6QlJNbVJDVTFkWmRreDVPSFpNZVRoMlN6RmFUbEZZZUcxT1JHTTBXbXBXYWs1cVdtMVphbXQ0VFcxTk5VNUhXVFZaYWxKdFRrZEpNVTFxVFhwWlYwWm9XWHBGTWxsWFdtcGFWRnBwVGtkUk1VMHlVWGxPUjBsNVdWZE5NMXBFUW1oYVJGazFUa1JWTWs1dFZUSm1SVFZHVmpOM1BRPT18VUhvNU5WUlhWbHBNTTBaTlZsTTRkbHA2TVdaTmFsWm1URlJHT0ZwWFNURlBSMXB0VFVkRk1VNTZaekZQUkVreldXcENiVmxxVm10YWFsSnRXV3BCZWxsdFdUUk9lbFUwV2tSb2FWbFhVVEZaYWtsNVRVZFZlRTR5V21sTlJFSnJXbFJGTWxsVVdteE5lbFpyVFcxRmVVNXVlRTlTVm1RNHwwYmNhMjZkNTdmYTUzMzA0MzEzM2Y1Yzg1OGZhZjY5NjMwNTc3MDUzNGRjM2FhNDhkNDQ4ZWIzNGYxODQ5YTA4fE5FV3w=')
效果
接下来我们就来欣赏一下我们得成果吧~
尾语
要成功,先发疯,下定决心往前冲!
学习是需要长期坚持的,一步一个脚印地走向未来!
未来的你一定会感谢今天学习的你。
—— 心灵鸡汤
本文章到这里就结束啦~感兴趣的小伙伴可以复制代码去试试哦
标签:小姐姐,img,get,python,18,bookmark,url,requests,data From: https://www.cnblogs.com/Qqun261823976/p/16794483.html