Python crawling King glory skin map

Time:2022-1-8

1、 Look at the effect first

Python crawling King glory skin map

2、 Tools

development environment

System: windows7 64 bit
Python version: 3.6
Pychar version: February 2019

interpreter

The official website address is:https://www.python.org
Python crawling King glory skin map

Software download ▼
sublime || JetBrains PyCharm Community Edition

3、 Get to the point

Page analysis website:

Hero information list page – Hero introduction – King glory official website – Tencent game

# requests
# json

import requests
import json

#Import module



# 1. Analyze the web page to determine the URL path
base_url = 'https://pvp.qq.com/web201605/js/herolist.json'

# 2. Send request -- requests simulates a browser sending a request to obtain response data
res = requests.get(base_url)
data = res.text
print(data)
# 3. Parsing data -- JSON module: convert JSON characters to Python interactive data types
#3.1 transfer data type
data_list = json.loads(data)
# print(data_list)
#3.2 parsing data
for data in data_list:
    # print(data)
    Ename = data ['ename '] # hero number
    CNAME = data ['cname '] # hero name

    try:
        skin_ name=data['skin_name']. Split ('|') # cut skin name is used to calculate how many skins
    except Exception as e:
        print(e)
    # print(ename,cname,skin_name)
    #Construct the URL and link address of all hero skin pictures
    # ' https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/ '+ hero number +' / '+ hero number +' - bigskin - '+ number of skin +' jpg'

    for skin_num in range(1,len(skin_name)+1):
        skin_url = 'https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/'+str(ename)+'/'+str(ename)+'-bigskin-'+str(skin_num)+'.jpg'
    # print(skin_url)
    skin_ data = requests. get(skin_url). Content # image acquisition binary
    # 4. Keep data -- save to destination folder
    with open('img\\'+cname+'-'+skin_name[skin_num-1]+'.jpg','wb') as f:
        Print ('downloading picture: ', CNAME +' - '+ skin_name [skin_num-1])
        f.write(skin_data)

Practical operation diagram

Python crawling King glory skin map