当前位置:网站首页>【Pyhton 实战】---- 批量【端午节】海报下载
【Pyhton 实战】---- 批量【端午节】海报下载
2022-06-09 10:02:00 【Rattenking】
1. 下载海报的网站选择
以稿定设计网站为例:
2. 查看海报列表的API
网页 —> 鼠标右键 —> 检查 【点击network,查看页面请求】

找到数据加载的api的方法,将页面下滑到底部,点击第二页,查找加载列表的接口,此网站的接口是【https://www.gaoding.com/api/v3/cp/template-centers/v2/recommend-templates】
3. 查看请求参数
点击当前接口,点击payload,就能找到接口的请求参数!
4. 查看请求头
点击当前接口,点击headers,就能找到接口的请求头!

5. 应用需要使用的库引入
import requests,json,time,random,os
6. 获取列表的接口和参数配置
url = 'https://www.gaoding.com/api/v3/cp/template-centers/v2/recommend-templates'
data = {
"page_num": 1,
"page_size": 50,
"styles": [],
"colors": [],
"filter_nodes": [
{
"type": 1,
"id": 4834126,
"children": [
{
"id": 4834127,
"type": 2,
"children": [
{
"agg_filter_id": 4834127,
"value": "1000002024"
}
]
},
{
"id": 4834128,
"type": 1
}
]
}
]
}
7. 请求头配置
headers = {
"content-type": "application/json;charset=UTF-8",
"x-channel-id": "8"
}
8. 创建存放海报的文件夹
"""创建存放海报的文件夹"""
def create_folder(path):
if not os.path.exists(path):
os.mkdir(path)
9. 获取海报列表
"""获取海报列表"""
def get_poster_list():
return requests.post(url, data=json.dumps(data1), headers=headers)
10. 保存海报
"""保存海报"""
def save_poster(url):
request = requests.get(url)
with open(f'./images/{int(round(time.time() * 1000))}-{random.randint(100,1000)}-poster.png', 'wb') as img:
img.write(request.content)
11. 下载海报
"""下载海报"""
def download_poster():
create_folder('./images')
res = get_poster_list()
for item in json.loads(res.text):
save_poster(item.get("preview").get("url"))
12. 完整代码
import requests,json,time,random,os
url = 'https://www.gaoding.com/api/v3/cp/template-centers/v2/recommend-templates'
data = {
"page_num": 1,
"page_size": 500,
"styles": [],
"colors": [],
"filter_nodes": [
{
"type": 1,
"id": 4834126,
"children": [
{
"id": 4834127,
"type": 2,
"children": [
{
"agg_filter_id": 4834127,
"value": "1000002024"
}
]
},
{
"id": 4834128,
"type": 1
}
]
}
]
}
headers = {
"content-type": "application/json;charset=UTF-8",
"x-channel-id": "8"
}
"""创建存放海报的文件夹"""
def create_folder(path):
if not os.path.exists(path):
os.mkdir(path)
"""获取海报列表"""
def get_poster_list():
return requests.post(url, data=json.dumps(data), headers=headers)
"""保存海报"""
def save_poster(url):
request = requests.get(url)
with open(f'./images/{int(round(time.time() * 1000))}-{random.randint(100,1000)}-poster.png', 'wb') as img:
img.write(request.content)
"""下载海报"""
def download_poster():
create_folder('./images')
res = get_poster_list()
for item in json.loads(res.text):
save_poster(item.get("preview").get("url"))
if __name__ == "__main__":
download_poster()
13. 运行预览

WXRUI体验二维码

下载
边栏推荐
- [image enhancement] image enhancement based on sparse representation and regularization with matlab code
- Query permission information from database
- Comparison between model sorting fields in laraveladmin
- Getting started with cloud based LDAP (Part 2)
- Web SSH client shwifty
- 从数据库查询权限信息
- WebAssembly 2022调查来啦
- golang_ 3_ structural morphology
- 失业潮?元宇宙开拓全新的就业机会
- ISCC2022 擂台misc
猜你喜欢

Key configuration points of video fusion cloud service easycvr platform deployed in ECS
![[genius_platform software platform development] lesson 35: UDP for cross network segment broadcasting](/img/53/c8d8b388788e13bdbf5cad9fbf91d6.png)
[genius_platform software platform development] lesson 35: UDP for cross network segment broadcasting

Lua call principle demonstration (Lua stack)

Interaction between C language and Lua (practice 2)

Kubernets chapitre 7: POD Advanced, Controller Advanced, Resource and Dashboard

Iscc2022 challenge arena Misc

关于在线帮助中心你需要思考以下几个问题
![Cyclic neural network theory -- [torch learning notes]](/img/42/4f9a70b707ad87d1f483129fea6e7e.png)
Cyclic neural network theory -- [torch learning notes]
![N-grams language model -- [torch learning notes]](/img/94/c5c4ac70590158b3c21d18c3b86a6f.png)
N-grams language model -- [torch learning notes]

安防监控视频EasyCVR视频调阅界面增加单个视频的关闭按钮
随机推荐
中信建投是安全的吗
自定义权限校验方法
Go strconv package
华泰证券是安全的吗
Stop watch today
Kubernets chapitre 7: POD Advanced, Controller Advanced, Resource and Dashboard
Construction of vocabulary and sampling -- [torch learning notes]
Publication of the prize for contribution - Essay solicitation activity for lightweight application server (April)
Some instructions in dict intersect with the difference sum in set, and increase or decrease elements
leetcode.36 --- 有效的数独
106. construct binary tree from middle order and post order traversal sequence
flutter 生成海报
Jincang of the National People's Congress won the recognition of "key software enterprises encouraged by the state" again
Interview question 01.06 String compression
Bidding solution for battery charging and discharging equipment
AppScan检查到的一些中高危漏洞解决方案
Sword finger offer 19 Regular expression matching recursion
其它权限校验方法
new和malloc区别和malloc详解
PIC simulation (particle in cell codes) (task a and task C)
