爬虫学习-爬LOL皮肤

孤街醉人 提交于 2020-02-28 19:15:24
# ! /sur/bin/python
# coding:utf-8
import re
import requests
import time


def get_hero_pic():
#图片URL = 固定+英雄ID+皮肤编号
#1 先获得英雄id
    res = requests.get("https://lol.qq.com/biz/hero/champion.js").text
    reg =r'"keys":(.*?),"data"'
    date = re.findall(reg,res)
    path =r'C:\Users\CF-54\Desktop\eas\pictures\\'
    hero_list = []
    url_list = []
    hero_list = []
    for hero_number,hero_name in eval(date[0]).items():
        #print(hero_number,hero_name) 显示编号和名字
        for i in range(15):
            hero_path = path+hero_name+"{:03}".format(i)+".jpg"
            hero_list.append(hero_path)
            hero_url = 'http://ossweb-img.qq.com/images/lol/web201310/skin/big'+hero_number+"{:03}".format(i)+".jpg"
            url_list.append(hero_url)
    #print(hero_list,url_list)
        hero_list.append(hero_name)
    #print(hero_list,url_list)

    n = 0
    for url,hero_pic,hero_n in zip(url_list,hero_list,hero_list):
        response = requests.get(url)
        if response.status_code == 200:
            n += 1
            print("正在下载{}的第{}张皮肤".format(hero_n,n))
            with open(hero_pic,"wb") as f:
                f.write(response.content)
        response.close()
        time.sleep(1)



get_hero_pic()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!