1 import re 2 import requests 3 4 # 读取本地的xml文件 5 with open('.\lol.txt', 'r', encoding='utf-8') as f: 6 for line in f: 7 if '"instance_id"' in line: 8 start_index = line.find('"instance_id"') + len('"instance_id"') 9 skin_id = line.split('"instance_id":"')[1].split('"')[0].replace('"', '') 10 11 # 将skin_id写入url中 12 url = f'https://game.gtimg.cn/images/lol/act/img/skinloading/{skin_id}.png' 13 14 # 下载并保存为PNG文件 15 response_png = requests.get(url) 16 with open(f'D:/vscode源码/lol/{skin_id}.png', 'wb') as f_png: 17 f_png.write(response_png.content) 18 19 # 下载并保存为JPG文件 20 url_jpg = url.replace('.png', '.jpg') 21 response_jpg = requests.get(url_jpg) 22 with open(f'D:/vscode源码/lol/{skin_id}.jpg', 'wb') as f_jpg: 23 f_jpg.write(response_jpg.content)
抓包了一段JSON文件,将文件内的游戏皮肤id先遍历出来,在加到链接中下载到本地。
遇到的问题:不确定需要下载的皮肤图片是png还是jpg,所以每张图片下载了两种格式,目前还不会判断预下载的文件格式,只能用笨办法了。
标签:读取,Python,jpg,url,lol,skin,随笔,id,png From: https://www.cnblogs.com/maya0214/p/17857779.html