import requests
import os
import re
from concurrent.futures import ThreadPoolExecutor
def download_img(eid, name, i, skin_name):
filename = f"王者荣耀壁纸/{eid:0>3}-{name}-{i:0>2}-{skin_name}.jpg"
print(filename)
if os.path.exists(filename):
return
img_url = f"http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{eid}/{eid}-bigskin-{i}.jpg"
res = requests.get(img_url)
with open(filename, "wb") as f:
f.write(res.content)
def download_hero_skin(hero):
eid, name = hero["ename"], hero["cname"]
res = requests.get(f"https://pvp.qq.com/web201605/herodetail/{eid}.shtml",
headers=headers)
res.encoding = "gbk"
skin_names = re.findall(
']+?data-imgname="([^"]+)"', res.text)[0].split("|")
print(eid, name, skin_names)
for i, skin_name in enumerate(skin_names, 1):
end = skin_name.find("&")
skin_name = skin_name[:len(skin_name) if end == -1 else end]
download_img(eid, name, i, skin_name)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'
}
herolist = requests.get(
"https://pvp.qq.com/web201605/js/herolist.json", headers=headers).json()
os.makedirs("王者荣耀壁纸", exist_ok=True)
with ThreadPoolExecutor(max_workers=16) as executor:
executor.map(download_hero_skin, herolist)