King of glory come crawling skin --py

Disclaimer: This article is CSDN blogger "~ wangweijun 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/qq_42453117/article/details/103190981

PS: If you think these things fun, you can go to my blog in a column, which has some of the more interesting I collect all kinds of programs or create their own
paper non-own, there is little change, delete invasion, thank you

introduction

King of glory all played it, never played should be heard, as among the most fire phone MOBA games, Keke, seems beside the point. Our focus today is the king of glory for all skin crawl all heroes, but using only 20 lines of Python code to complete.

Code

##requests模块的安装
##1、 pip命令安装
##windows系统下只需要在命令行输入命令 pip install requests 即可安装
##在 linux 系统下,只需要输入命令 sudo pip install requests ,即可安装。
##2、下载安装包安装
##由于pip命令可能安装失败所以有时我们要通过下载第三方库文件来进行安装。
##在github上的地址为:https://github.com/requests/requests 
##下载文件到本地之后,解压到python安装目录。 
##之后打开解压文件,在此处运行命令行并输入:python setup.py install 即可。
##之后我们测试requests模块是否安装正确,在交互式环境中输入 import requests
## 如果没有任何报错,说明requests模块我们已经安装成功了
##
##requests.request()	构造一个请求,支持以下各种方法
##requests.get()	获取html的主要方法
##requests.head()	获取html头部信息的主要方法
##requests.post()	向html网页提交post请求的方法
##requests.put()	向html网页提交put请求的方法
##requests.patch()	向html提交局部修改的请求
##requests.delete()	向html提交删除请求

import os
import requests

url = 'https://pvp.qq.com/web201605/js/herolist.json'
herolist = requests.get(url)  # 获取英雄列表json文件

herolist_json = herolist.json()  # 转化为json格式
hero_name = list(map(lambda x: x['cname'], herolist.json()))  # 提取英雄的名字
hero_number = list(map(lambda x: x['ename'], herolist.json()))  # 提取英雄的编号


# 下载图片
def downloadPic():
    i = 0
    for j in hero_number:
        # 创建文件夹
        os.mkdir("D:\\王者荣耀所有英雄皮肤\\" + hero_name[i])                                      #下载好之后就在D盘下面,你也可以改一下路径
        # 进入创建好的文件夹
        os.chdir("D:\\王者荣耀所有英雄皮肤\\" + hero_name[i])
        i += 1
        for k in range(10):
            # 拼接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)  # 请求url
            if im.status_code == 200:
                open(str(k) + '.jpg', 'wb').write(im.content)  # 写入文件


downloadPic()

Here Insert Picture Description
Here Insert Picture Description

Write code that can be directly linked with: https: //pan.baidu.com/s/1oPqKSj7OPVR8ODZsF8dT8A extraction code: m94m

Published 29 original articles · won praise 13 · views 2753

Guess you like

Origin blog.csdn.net/zmx2473162621/article/details/103423735