'''
网址:https://101.qq.com/#/hero
'''
import aiohttp
import asyncio
import json
import os
class LOL:
request_url = {
'hero_info': 'https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js?ts=2822604',
'skin': 'https://game.gtimg.cn/images/lol/act/img/skin/big{}00{}.jpg'
}
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
}
def __init__(self):
pass
async def get_hero(self):
async with aiohttp.ClientSession(headers=self.headers) as request:
response = await request.get(self.request_url['hero_info'])
hero_json_str = await response.text()
task_list = []
for item in json.loads(hero_json_str)['hero']:
task = asyncio.create_task(self.get_skin(request,item))
task_list.append(task)
await asyncio.wait(task_list)
async def get_skin(self,request,hero_info):
path = f'img{os.sep}{hero_info["name"]}'
if not os.path.exists(path):
os.makedirs(path)
for nu in range(30):
response = await request.get(self.request_url['skin'].format(hero_info['heroId'], nu),headers=self.headers)
if response.status == 200:
skin_info = await response.read()
with open(f'{path}{os.sep}{nu}.jpg', 'wb') as file:
file.write(skin_info)
print('英雄皮肤已下载')
else:
break
if __name__ == '__main__':
lol = LOL()
asyncio.run(lol.get_hero())
没有合适的资源?快使用搜索试试~ 我知道了~
python英雄联盟皮肤爬取案例
共2个文件
py:2个
需积分: 1 0 下载量 104 浏览量
2024-03-20
13:57:00
上传
评论
收藏 2KB ZIP 举报
温馨提示
该资源是一个常见的网络爬虫案例,可以用来获取英雄联盟游戏中的英雄、皮肤或者游戏截图等图片资源;python版本3.11.7,主要使用aiohttp、 asyncio、json、os等库
资源推荐
资源详情
资源评论
收起资源包目录
英雄联盟图片爬取.zip (2个子文件)
英雄联盟
web.py 695B
skin.py 2KB
共 2 条
- 1
资源评论
局外人LZ
- 粉丝: 5138
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功