当前位置:网站首页>[pyhton practice] - batch [Dragon Boat Festival] poster Download

[pyhton practice] - batch [Dragon Boat Festival] poster Download

2022-06-09 10:43:00 Rattenking

1. Choose a website to download posters

Take the draft design website as an example :
 Insert picture description here

2. View the poster list API

Webpage —> Right mouse button —> Check 【 Click on network, View page requests 】

 Insert picture description here

Find the data loaded api Methods , Slide the page down to the bottom , Click on page two , Find the interface to load the list , The interface of this website is 【https://www.gaoding.com/api/v3/cp/template-centers/v2/recommend-templates】

3. View request parameters

Click the current interface , Click on payload, You can find the request parameters of the interface !
 Insert picture description here

4. Check the request header

Click the current interface , Click on headers, You can find the request header of the interface !

 Insert picture description here

5. The application needs to use the library to import

import requests,json,time,random,os

6. Get the interface and parameter configuration of the list

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. Request header configuration

headers = {
  "content-type": "application/json;charset=UTF-8",
  "x-channel-id": "8"
}

8. Create a folder for posters

""" Create a folder for posters """
def create_folder(path):
  if not os.path.exists(path):
    os.mkdir(path)

9. Get poster list

""" Get poster list """
def get_poster_list():
  return requests.post(url, data=json.dumps(data1), headers=headers)

10. Save the poster

""" Save the poster """
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. Download the posters

""" Download the posters """
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. Complete code

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"
}

""" Create a folder for posters """
def create_folder(path):
  if not os.path.exists(path):
    os.mkdir(path)

""" Get poster list """
def get_poster_list():
  return requests.post(url, data=json.dumps(data), headers=headers)

""" Save the poster """
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)

""" Download the posters """
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. Run Preview

 Insert picture description here

WXRUI Experience QR code

WXRUI Experience code

download

My blog , Welcome to exchange !

my CSDN Blog , Welcome to exchange !

Wechat applet column

Front end note column

Wechat applet realizes some functions of Gaode map DEMO download

Wechat applet implementation MUI Partial effect of DEMO download

Wechat applet implementation MUI Of GIT Project address

Wechat applet instance list

Front end note list

Game list

原网站

版权声明
本文为[Rattenking]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091002157506.html