代码拉取完成,页面将自动刷新
# -*- coding: UTF-8 -*-
"""
@Project :LOL
@File :download_pic.py
@Author :xiaoer
@Date :2021/10/28 8:52
@desc:
"""
import requests
from multiprocessing.dummy import Pool as ThreadPool
import time
import os
import json
headers = {
'authority': 'aegis.qq.com',
'sec-ch-ua': '"Microsoft Edge";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.30',
'sec-ch-ua-platform': '"Windows"',
'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary9qCcB1thg6Mfr2qd',
'accept': '*/*',
'origin': 'https://lol.qq.com',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://lol.qq.com/',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
}
def spider(url):
res = requests.get(url, headers=headers)
result = res.content.decode('utf-8')
res_dict = json.loads(result)
skins = res_dict['skins']
for index, hero in enumerate(skins):
item = dict()
item['name'] = hero['heroName']
item['skin_name'] = hero['name']
if hero['mainImg'] == '':
continue
item['imgLink'] = hero['mainImg']
print(item)
download(index + 1, item)
def download(index, contdict):
name = contdict['name']
path = '皮肤/' + name
if not os.path.exists(path):
os.makedirs(path)
content = requests.get(contdict['imgLink'], headers=headers).content
with open('./皮肤/' + name + '/' + contdict['skin_name'].replace('/', '') + str(index) + '.jpg', 'wb') as f:
f.write(content)
def main():
url1 = 'https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js'
text = requests.get(url1, headers=headers).text
# print(text)
json_loads = json.loads(text)
loads_get = json_loads.get("hero")
hero_ids = []
# print(loads_get)
for i in loads_get:
# print(i.get('heroId'))
hero_id = i.get('heroId')
hero_ids.append(hero_id)
print(hero_ids)
start = time.time()
pool = ThreadPool(6)
page = []
for i in hero_ids:
newpage = 'https://game.gtimg.cn/images/lol/act/img/js/hero/{}.js'.format(i)
print(newpage)
page.append(newpage)
pool.map(spider, page)
pool.close()
pool.join()
print(time.time()-start)
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。