# ! /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()
来源:https://www.cnblogs.com/mmdlife/p/10824145.html