Akik Look at that coder

Public account: Look at that code farmer

1. Project Introduction

As the most popular mobile game at the moment, our focus today is to crawl all the skins of all the heroes of King of Glory, and only 20 lines of Python code to do it.

2. Project Purpose

Climb all the skin of all Kings of Glory heroes

3. Project process

1. Preparation

The skin itself is not difficult to climb, the difficulty lies in the analysis, we first need to get the URL of the skin image, we first go to the official website of King of Glory:

Click game information – > Hero information, randomly select a hero, such as “Chang ‘e”.

Enter the hero skin page, then press F12 to open the debugging console, find the hero original skin picture address:

The location of chang ‘e’s skin is linked to:

http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/515/515-bigskin-2.jpg
Copy the code

Then, when we switch the hero’s skin, we will find that there is no obvious change in the picture address, only the number of the last number is changed. We will continue to intercept other chang ‘e skin address links according to the same operation above:

The location of chang ‘e’s skin is linked to:

# Chang 'e is like a dreamhttp://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/515/515-bigskin-3.jpg# Chang 'e dew flower reflection skinhttp://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/515/515-bigskin-2.jpg# Chang 'e Cold Moon princess skinhttp://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/515/515-bigskin-1.jpg
Copy the code

We compare the addresses of the three skin pictures of the same hero together. For the address of the skin picture of the same hero, only the final number is different, and the path of the skin picture of the same hero increases successively from 1.

King of glory official website Hou Yi hero link

https://pvp.qq.com/web201605/herodetail/169.shtml
Copy the code

King of Glory official website Chang ‘e hero link

https://pvp.qq.com/web201605/herodetail/515.shtml
Copy the code

Then respectively open “Houyi” and “Chang ‘e” hero link, the comparison of links, you can find that the difference between heroes is the number of links behind.

Once we’ve found the link patterns for different heroes, and for different skins of the same hero, we can start coding the functionality.

2. Code implementation

Based on Python3. X

First we create a Python file, then import the OS and requests modules.

Following the previous steps, we first need to get the herolist information, which is the herolist.json file.

The file address is pvp.qq.com/web201605/j…

This can be found in the debug console.

We will first get the JSON data of the hero list information from this address, and then parse the JSON data to extract the useful information:

url = 'https://pvp.qq.com/web201605/js/herolist.json'Herolist = requests. Get (url) # herolist_json = herolist.json() # convert hero_name = list(map(lambda x: x['cname'], herolist.json())) # retrieve hero_number = list(map(lambda x: x]'ename'], herolist.json())) #Copy the code

Once you have the hero number, it’s easy to concatenate the URL:

http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/' + hero_number + '/' + hero_number + '-bigskin-1.jpg
Copy the code

So we can get all the skin of the hero image, but there will be a problem, the hero of the skin is more with less, some heroes only two skin, some have six or seven, so pictures a maximum number of we don’t know, here I have adopted a more stupid way, is to make a variable from 1 to 10, in turn, increasing to stitching images address, If there are no images we don’t deal with them, because no hero has more than 10 skins, so we get all the images. Create a new folder on your desktop and call it wzry.

Def downloadPic(): I =0
    for j inHero_number: # create folder os.mkdir("C:\\Users\\Administrator\\Desktop\\wzry\\"+ hero_name[I]) # enter the created folder os.chdir("C:\\Users\\Administrator\\Desktop\\wzry\\" + hero_name[i])
        i += 1
        for k in range(10): # concatenate the URL onehero_link ='http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/' + str(j) + '/' + str(
                j) + '-bigskin-' + str(k) + '.jpg'Im = requests. Get (onehero_link) # request urlif im.status_code == 200:
                open(str(k) + '.jpg'.'wb').write(im.content) # Write fileCopy the code

The complete code of the whole program is as follows:

import os
import requests

url = 'https://pvp.qq.com/web201605/js/herolist.json'Herolist = requests. Get (url) # herolist_json = herolist.json() # convert hero_name = list(map(lambda x: x['cname'], herolist.json())) # retrieve hero_number = list(map(lambda x: x]'ename'], herolist.json())) def downloadPic(): I =0
    for j inHero_number: # create folder os.mkdir("C:\\Users\\Administrator\\Desktop\\wzry\\"+ hero_name[I]) # enter the created folder os.chdir("C:\\Users\\Administrator\\Desktop\\wzry\\" + hero_name[i])
        i += 1
        for k in range(10): # concatenate the URL onehero_link ='http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/' + str(j) + '/' + str(
                j) + '-bigskin-' + str(k) + '.jpg'Im = requests. Get (onehero_link) # request urlif im.status_code == 200:
                open(str(k) + '.jpg'.'wb').write(im.content) # Write a file downloadPic()Copy the code

Finally running the program, we can get the full hero skin we want to collect

4. Project Purpose

In the training process of algorithm model of deep learning and machine learning, a large number of other images of the same type need to be downloaded as data sets.

We can rely on the crawler to crawl, reduce the amount of artificial labor

5. Summarize and think

The project can build on this to improve the crawl process

At the same time, GUI design is optimized to achieve human-computer interaction

Facilitate the process of calling a program

If you find this helpful:

1. Click “like” to support it, so that more people can see this article

2, pay attention to the public number: look at that code farmers, we study together and progress together.

This article is participating in the “Nuggets 2021 Spring Recruitment Campaign”, click to see the details of the campaign