Python随笔之英雄联盟皮肤、炫彩爬取练习
翻了网上爬皮肤的帖子,很多都是爬英雄的皮肤,没有获取到炫彩皮肤的文件
以下代码就是先获取所有的英雄id,再拼接成新的链接再遍历
把获取到的数据保存CSV文件到本地
(之前从事过游戏账号交易行业,还有很多商家有截取皮肤资产的需求,盼之和螃蟹的解决方案成本有点高,以后写一个简单实现的^^)
import requests import csv url = "***/lol/act/img/js/heroList/hero_list.js" response = requests.get(url) response.encoding = "utf-8" # 在这里处理 JSON 数据 json_data = response.json() # 提取 heroId hero_info = {} for hero in json_data['hero']: hero_id = hero['heroId'] hero_url = f"***/lol/act/img/js/hero/{hero_id}.js" skin_data = requests.get(hero_url).json() myskin = skin_data['skins'] # 将拼接的js链接进行遍历 for skin in myskin: skinid = skin['skinId'] heroid = skin['heroId'] skinname = skin['name'] herotitle = skin['heroTitle'] chromas = skin['chromas'] chromasBelongId = skin['chromasBelongId'] heroloadpic = skin['loadingImg'] chromaimg = skin['chromaImg'] # 将数据写入 CSV 文件 with open('hero_skin.csv', 'a', newline='', encoding='utf-8') as f: writer = csv.writer(f) writer.writerow([skinid, heroid, skinname, herotitle, chromas, chromasBelongId, heroloadpic, chromaimg]) print(f'{skinname}写入成功')
暂时没有写下载,全都存到本地应该有几个G
浙公网安备 33010602011771号