python爬取LOL皮肤

代码

import requests
import re
import time

def Download_LOL_Skin():
    json_url = "https://lol.qq.com/biz/hero/champion.js"
    html_re = requests.get(json_url).content
    html_str = html_re.decode()
    pat_js = r'"keys":(.*?),"data"'
    enc = re.compile(pat_js)
    html_list = enc.findall(html_str)
    dict_js = eval(html_list[0])
    download_url = []
    for key in dict_js:
        for i in range(15):
            hero_str = str(i)
            if len(hero_str)==1:
                num = '00'
            elif len(hero_str)==2:
                num = '0'
            numstr = key + num + hero_str
            hero_download_url = r'https://ossweb-img.qq.com/images/lol/web201310/skin/big' + numstr +'.jpg'
            download_url.append(hero_download_url)
    file_path_list = []
    path = 'D:/LOL_SKIN'
    for name in dict_js.values():
        for i in range(15):
            file_path = path + name + str(i) + '.jpg'
            file_path_list.append(file_path)
    n = 1
    for i in range(len(download_url)):
        status_code = requests.get(download_url[i]).status_code
        if status_code == 200:
            res = requests.get(download_url[i],verify = False).content
            with open(file_path_list[i],"wb") as f:
                f.write(res)
            print(download_url[i] + "第" + str(n) + "张下载完成")
            n = n+1
    print("共" + str(n) + "张图片下载完毕")
if __name__=='__main__':
    start = time.time()
    Download_LOL_Skin()
    end = time.time()
    print("用时" + str(end-start) + "秒")
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值