自从学了python,我再也不缺英雄联盟的皮肤了
最近在玩英雄联盟,在官网上面看到不同英雄的皮肤,感觉设计的很不错,就想保存下来当做桌面背景。一张张下载的话速度太慢了,所以就用python写了个代码爬取了一下。
# -*- coding: utf-8 -*-
import requests
import asyncio
import os
from aiohttp import ClientSession
import aiohttp
import json
from datetime import datetime
async def skins_downloader(semaphore, hero_id, hero_name):
async with semaphore:
url = 'https://game.gtimg.cn/images/lol/act/img/js/hero/{}.js'.format(hero_id)
dir_name = 'skins/{}'.format(hero_name)
if not os.path.exists(dir_name):
os.mkdir(dir_name)
async with ClientSession(connector=aiohttp.TCPConnector(ssl=False)) as session:
async with session.get(url) as response:
response = await response.read()
for skin in json.loads(response)['skins']:
if skin['mainImg']:
img_url = skin['mainImg']
# kda女团皮肤名带斜杠,replace掉
path = os.path.join(dir_name, '{}.jpg'.format(skin['name'].replace('/', ''), ))
async with session.get(img_url) as skin_response:
with open(path, 'wb') as f:
print('\rDownloading [{:^10}] {:<20}'.format(hero_name, skin['name']), end='')
f.write(await skin_response.read())
def hero_list():
return requests.get('https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js').json()['hero']
async def run():
semaphore = asyncio.Semaphore(30)
heroes = hero_list()
tasks = []
for hero in heroes:
tasks.append(asyncio.ensure_future(skins_downloader(semaphore, hero['heroId'], hero['title'])))
await asyncio.wait(tasks)
if __name__ == '__main__':
start_time = datetime.now()
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
loop.close()
end_time = datetime.now()
time_diff = (end_time - start_time).seconds
print('\nTime cost: {}s'.format(time_diff))
自从我用了你的方法,我以后再也不能玩英雄联盟了 https://oohuo.lanzouj.com/ipFA4i9psvg
打包好的exe地址,下载后在当前文件夹创建一个“skins”文件夹,双击运行即可
有帮助麻烦给个热心
有帮助麻烦给个热心
有帮助麻烦给个热心
有帮助麻烦给个热心 堕落神棍 发表于 2020-11-10 23:14
没看到skins文件夹
他的意思是,需要你自己新建一个名为“skins”的文件夹 要是有打包的exe文件就好了,配置python环境太难了,还需要很多模块{:301_979:} 兄弟,編譯一個exe啊,在綫等,挺急的! 都从游戏开始的兴趣 Oohuo 发表于 2020-11-10 23:02
https://oohuo.lanzouj.com/ipFA4i9psvg
打包好的exe地址,下载后在当前文件夹创建一个“skins”文件夹, ...
试一试看看效果 Oohuo 发表于 2020-11-10 23:02
https://oohuo.lanzouj.com/ipFA4i9psvg
打包好的exe地址,下载后在当前文件夹创建一个“skins”文件夹, ...
没看到skins文件夹 ll018213 发表于 2020-11-10 22:32
要是有打包的exe文件就好了,配置python环境太难了,还需要很多模块
打包一点点代码打包下来太大了。