1 Star 0 Fork 1

Demik/python文档

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
download_pic.py 2.49 KB
一键复制 编辑 原始数据 按行查看 历史
qjl 提交于 2021-10-28 15:58 . update
# -*- 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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/demik/pytest.git
git@gitee.com:demik/pytest.git
demik
pytest
python文档
master

搜索帮助