将图片按照每个英雄一个文件夹分类,存到代码文件相同目录下的王者荣耀目录下

import os
import requests

url = 'https://pvp.qq.com/web201605/js/herolist.json'
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (HTML5, like Gecko) Chrome/95.0.4638.69 Safari/537.36'
}
res = requests.get(url=url,headers=headers).json()
os.mkdir('./王者荣耀')
for i in res:
    id = i['ename']
    name = i['cname']
    os.mkdir('./王者荣耀/'+name)
    for i in range(1,10):
        img_url = 'https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/%s/%s-bigskin-%s.jpg'%(str(id),str(id),str(i))
        img_data = requests.get(url=img_url,headers=headers)
        if img_data.status_code ==200:
            path = './王者荣耀/'+name+'/'+str(i)+'.jpg'
            with open(path,'wb') as f:
                f.write(img_data.content)
最后修改:2022 年 08 月 31 日
如果觉得我的文章对你有用,请随意赞赏