LOL爬虫小工具是一个利用python指定爬取LOL高清壁纸、皮肤图片、头像图片、图标等下载工具,通过网上的爬虫教程结合爱好写了个爬虫,能爬取LOL国服官网资料库里的图片。研究了一下python,写出了这么个小东西。
爬取英雄联盟高清图片
运行结果
# coding=utf-8
import requests
import re
import json
import os
import urllib
import time
import threading
from queue import Queue
def getHttpStatusCode(url):
try:
request = requests.get(url)
httpStatusCode = request.status_code
return httpStatusCode
except requests.exceptions.HTTPError as e:
return e
def Get_Hero_Jsurl(queue):
url = 'https://lol.qq.com/biz/hero/champion.js'
response = requests.get(url).content.decode('gb2312')
regular = r'data":(.*?),"version":"'
dict_js = json.loads(re.findall(regular, response)[0])
for _item in dict_js:
EN = dict_js[_item]['id']
queue.put(EN.format(id=_item))
def Stitching_JS_links(name_en):
link = 'https://lol.qq.com/biz/hero/{}.js'.format(name_en)
return link
def Parsing_hero_JS(url):
response = requests.get(url).content.decode('gb2312')
regular = r'data":(.*?),"version":"'
js_data = json.loads(re.findall(regular, response)[0])
result = {
'name_CN': js_data['name'] + ' ' + js_data['title'],
'name_EN': js_data['id'],
'skins': js_data['skins'],
'skill': js_data['spells'],
'passive': js_data['passive'],
}
return result
def Download_hero_resources(detail_url_list: Queue, id):
while len(detail_url_list.queue):
hero_name = detail_url_list.get()
Metadata = Parsing_hero_JS(Stitching_JS_links(hero_name))
path = os.getcwd() + '⁄⁄英雄相关⁄⁄' + Metadata['name_CN']
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 + '⁄⁄技能')
# 下载皮肤和头像图 [img]https://game.gtimg.cn/images/lol/act/img/skin/big1000.jpg[/img]
for item_skin in Metadata['skins']:
url_0 = 'https://game.gtimg.cn/images/lol/act/img/skin/big{}.jpg'.format(
item_skin['id'])
url_1 = 'https://game.gtimg.cn/images/lol/act/img/skin/small{}.jpg'.format(
item_skin['id'])
urllib.request.urlretrieve(
url_0,
path + '⁄⁄皮肤⁄⁄' + item_skin['name'].replace('/', '') + '.jpg')
urllib.request.urlretrieve(
url_1,
path + '⁄⁄头像⁄⁄' + item_skin['name'].replace('/', '') + '.jpg')
pass
# 下载技能图 [img]https://game.gtimg.cn/images/lol/act/img/spell/AnnieR.png[/img]
for item_skill in Metadata['skill']:
url_3 = 'https://game.gtimg.cn/images/lol/act/img/spell/{}.png'.format(
item_skill['id'])
save_path = path + '⁄⁄技能⁄⁄' + item_skill[
'name'] + '_' + item_skill['id'].replace(hero_name,
'') + '.png'
if (getHttpStatusCode(url_3) != 404):
urllib.request.urlretrieve(url_3, save_path.replace('/', '-'))
url_3 = 'https://game.gtimg.cn/images/lol/act/img/passive/{}'.format(
Metadata['passive']['image']['full'])
if (getHttpStatusCode(url_3) == 404):
url_3 = 'https://game.gtimg.cn/images/lol/act/img/spell/{}'.format(
Metadata['passive']['image']['full'])
save_path = path + '⁄⁄技能⁄⁄' + Metadata['passive'][
'name'] + '_P' + '.png'
# test = getHttpStatusCode(url_3)
urllib.request.urlretrieve(url_3, save_path.replace('/', '-'))
def Features_1():
detail_url_queue = Queue(maxsize=1000)
thread = threading.Thread(target=Get_Hero_Jsurl, args=(detail_url_queue, ))
html_thread = []
thread.start()
for i in range(20):
thread2 = threading.Thread(target=Download_hero_resources,
args=(detail_url_queue, i))
html_thread.软件end(thread2)
start_time = time.time()
print('将在2秒后启动多线程下载')
time.sleep(2)
for i in range(20):
html_thread[i].start()
sum_num = len(detail_url_queue.queue)
thread.join()
for i in range(20):
html_thread[i].join()
time_ = time.time() - start_time
print('共下载了{}位英雄资源'.format(sum_num))
print("用时: {}分{}秒".format(int(time_ // 60), int(time_ % 60) + 1))
def Features_2():
hero_js = 'https://lol.qq.com/biz/hero/item.js'
response = requests.get(hero_js).content.decode('gb2312')
正则 = r'data":(.*?),"tree'
list_js = re.findall(正则, response)
dict_js = json.loads(list_js[0])
Item_name = {}
Item_url = {}
if not os.path.exists(os.getcwd() + '⁄⁄装备'):
os.makedirs(os.getcwd() + '⁄⁄装备')
for i in dict_js:
Item_name[i] = dict_js[i]['name']
url0 = 'https://game.gtimg.cn/images/lol/act/img/item/'
url1 = '.png'
Item_url[i] = url0 + i + url1
p = 0
for i in Item_url:
urllib.request.urlretrieve(
Item_url[i],
os.getcwd() + '⁄⁄装备⁄⁄' + Item_name[i] + '.png')
p += 1
_JD = (p / len(Item_url)) * 100
print('已完成 ', end='')
print('%.2lf' % _JD, end=' %⁄n')
def main():
print('LOL爬虫小工具 作者:艾斯托维亚')
print('———————————————————————————————————————')
print(' 1 | 从官网下载最新英雄头像、皮肤原画、技能图标')
print(' 2 | 从官网下载最新最新装备图 ')
print('———————————————————————————————————————')
n = input('请输入数字以选择功能⁄n')
n = int(n)
if n > 0 and n < 3:
swicth = {
1: Features_1,
2: Features_2,
}
swicth[n]()
input('数据保存在app同目录⁄n按随意键退出⁄n')
else:
print('错误输入⁄n程序即将退出')
time.sleep(2)
if __name__ == "__main__":
main()
LOL英雄联盟是目前非常火爆的一款DotA类大型多人在线竞技网游,lol的热潮依然未过,它依然是最受玩家喜爱的大型多人在线竞技游戏,随之衍生出了许多游戏辅助工具,在此我们将搜集各类常用英雄联盟辅助工具提供给大家,包括LOL多玩盒子,178大脚插件等知名辅助集合,以及各类LOL相关脚本及实用工具,我们给大家提供方便快捷的lol辅助工具下载!
LOL盒子 | 18.20MB
2020-08-03
下载游戏助手 | 1.70MB
2020-07-17
下载QQ表情 | 1.20MB
2017-05-23
下载QQ表情 | 10.60MB
2017-05-23
下载端游辅助 | 2.20MB
2017-04-05
下载QQ表情 | 456.00KB
2017-03-29
下载端游辅助 | 18.50MB
2017-03-24
下载端游辅助 | 18.50MB
2017-03-24
下载端游辅助 | 14.88MB
2017-03-22
下载端游辅助 | 12.45MB
2017-03-20
下载