其他分享
首页 > 其他分享> > 爬取王者荣耀皮肤图片

爬取王者荣耀皮肤图片

作者:互联网

笔记

# coding : utf8
import requests
import time
import os
import json
import shutil


start = time.time()
url = requests.get('https://pvp.qq.com/web201605/js/herolist.json').content
jsonfile = json.loads(url)
print(jsonfile)


x=0
hero_dir= "H:/python_project/image/"
if not os.path.exists(hero_dir) :
    os.mkdir(hero_dir)
    print("mkdir succ")
else:
    if not os.listdir(hero_dir):
        print("dir is empty")
    else:
        shutil.rmtree(hero_dir)
        os.mkdir(hero_dir)
        print("dir already exists")


for m in range(len(jsonfile)):
    ename = jsonfile[m]["ename"]
    cname = jsonfile[m]['cname']
    skinName = jsonfile[m]['skin_name'].split('|')
    skinNumber = len(skinName)
    for bigskin in range(1,skinNumber+1):
        urlPicture = 'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/'+str(ename)+'/'+str(ename)+'-bigskin-'+str(bigskin)+'.jpg'
        picture=requests.get(urlPicture).content

        with open(hero_dir+cname+ "-"+ skinName[bigskin-1]+ ".jpg","wb") as f :
            f.write(picture)
            x+=1
            print("正在下载....第"+ str(x)+ "张")
end = time.time()

execution_time= end-start
print("共下载"+str(x)+ "张","共耗时"+str(execution_time)+ "秒")


标签:hero,王者,荣耀,爬取,str,time,print,jsonfile,dir
来源: https://blog.csdn.net/qq_42840111/article/details/113191803