python爬取lol所有英雄皮肤和英雄的语音包

        打开wegame想来把lol的阿卡丽,之前因为the thy 才喜欢上玩这个人物,忽然发现wegame跳出一个页面,我记得以前一直没有,估计是更新了吧

       看到时间我惊呆了,没想到lol陪伴了我这么久了,1848天了,大概5年了,忽然想起了渣渣辉了,哈哈,看到里面的英雄一个个那么熟悉还有那绚丽的皮肤,有很多已经下线了,所以我就写了一个脚本,爬取所有的皮肤图片保存起来,顺便还爬取了每个英雄的语音包,哈哈,算是意外收获了

皮肤: 每个英雄的皮肤都保存在一个文件夹,然后把所有的文件放在皮肤专栏里,方便查找

语音包:把每个英雄的游戏语音放在一起,方便查找


代码如下:喜欢的小伙伴拿去用吧

import requests
import time
import re
import os
import pprint

# 总文件夹
path = 'lol/'
if not os.path.exists(path):
    os.makedirs(path)

# 音频子文件夹
if not os.path.exists(path + '全英雄音频'):
    os.makedirs(path + '全英雄音频')

# 皮肤子文件夹
if not os.path.exists(path + '全英雄皮肤/'):
    os.makedirs(path + '全英雄皮肤/')

for dd in range(1, 151):
    time.sleep(2)
    url = 'https://game.gtimg.cn/images/lol/act/img/js/hero/' + str(dd) + '.js'
    headers = {
        'cookie': 'pgv_pvi=3828179968; RK=OSDMHVB5T0; ptcz=81335f4ff32bef89edd292edfcab2851d1a6ce69ce4888698a6d8420f2c8d328; pgv_pvid=1170630744; [email protected]; o_cookie=429984201; pac_uid=1_429984201; ied_qq=o0429984201; pgv_info=ssid=s6113272956; pgv_si=s9295807488; uin=o0429984201; skey=@6Sw6qstGG; eas_sid=H185k9J7Q2z1W1V2w7h1S6O0x1; isHostDate=18486; PTTuserFirstTime=1597190400000; isActDate=18486; PTTactFirstTime=1597190400000; ts_uid=1170630744; weekloop=0-0-0-33; tokenParams=%3Fid%3D1; ts_last=lol.qq.com/main.shtml; lolqqcomrouteLine=main_data_main; gpmtips_cfg=%7B%22iSendApi%22%3A0%2C%22iShowCount%22%3A0%2C%22iOnlineCount%22%3A0%2C%22iSendOneCount%22%3A0%2C%22iShowAllCount%22%3A0%2C%22iHomeCount%22%3A0%7D',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
    }
    response = requests.get(url=url, headers=headers)
    response.encoding = response.apparent_encoding
    # pprint.pprint(response.json())

    # 英雄语音下载
    hero = response.json()['hero']
    banAudio_url = hero['banAudio']
    selectAudio_url = hero['selectAudio']
    name = hero['name']
    Voice_1 = name
    Voice_2 = name
    title = hero['title']
    # print('名字:', name, '小名:', title, '音频1:', selectAudio, '音频2:', banAudio)
    response_1 = requests.get(url=banAudio_url, headers=headers)
    response_2 = requests.get(url=selectAudio_url, headers=headers)
    with open(path + '全英雄音频//' + Voice_1 + '1' + '.mp3', mode='wb')as f:
        f.write(response_1.content)
    with open(path + '全英雄音频//' + Voice_2 + '2' + '.mp3', mode='wb')as f:
        f.write(response_2.content)
        print('音频下载完成:', name, title)

    # 英雄皮肤图片下载
    skinss = response.json()['skins']
    for skins in skinss:
        # print(skins)
        heroName = skins['heroName']  # 名字
        heroTitle = skins['heroTitle']  # 小名
        mainImgs_url = skins['mainImg']  # 皮肤 url
        if mainImgs_url == '':
            continue
        print(mainImgs_url)
        name = skins['name']  # 皮肤名字
        skin = name
        response_mainImgs = requests.get(url=mainImgs_url, headers=headers).content
        # print('名字', heroName, '小名', heroTitle)
        # 皮肤子文件

        try:
            if not os.path.exists(path + '全英雄皮肤/' + heroName + '/'):
                os.makedirs(path + '全英雄皮肤/' + heroName + '/')
            with open(path + '全英雄皮肤/' + heroName + '/' + skin + '.jpg', mode='wb') as f:
                f.write(response_mainImgs)
                print('皮肤下载完成:', skin)
        except:
            print('皮肤下载失败:', skin)

若有侵权与我联系

猜你喜欢

转载自blog.csdn.net/Green_F/article/details/107977127