Python爬取LOL英雄皮肤
Python爬取LOL英雄皮肤
一 实现分析
- 在官网上找到英雄皮肤的真实链接,查看多个后发现前缀相同,后面对应为英雄的ID和皮肤的ID,皮肤的ID从00开始顺序递增,而英雄ID跟网页中的顺序无关,需要找到英雄ID。
- 并没有在皮肤页面和英雄页面的元素中找到有关英雄ID的内容,所以想到有可能是通过js文件加载进来的。通过Chrome工具找到跟英雄ID有关的js文件网址。
- 通过js文件网址获得英雄ID。与图片真实网址进行拼接,得到所有英雄的所有皮肤的图片地址,保存到列表中。
- 设置图片保存的路径和文件名。
- 下载。
二 知识点与难点
- 通过re库来正则表达式的处理。
- 通过json将字符串转成字典类型。
- 图片地址和文件名称的拼接。
- 判断图片是否真实存在和下载。
三 代码
- '''
- 1. 找到图片路径,获取所有图片真实URL
- 2. 设置文件名
- 3. 下载
- '''
- import requests
- import re
- import json
- def getLOLImages():
- # 包含英雄名字和ID的js文件路径
- js_url = "http://lol.qq.com/biz/hero/champion.js"
- # 获取js文件内容
- js_content = requests.get(js_url).text
- # 截取需要的内容 .*? 代表所有内容
- req = '"keys":(.*?),"data"'
- # 取到的是列表,真正想要的是列表中的第一个元素
- js_want = re.findall(req, js_content)[0]
- # 转成字典形式
- js_dict = json.loads(js_want)
- # 获取图片的真实URL,并保存到列表中
- # http://ossweb-img.qq.com/images/lol/web201310/skin/big266000.jpg
- pic_url_list = []
- for hero_id in js_dict:
- for skin_id in range(20):
- skin_id = str(skin_id)
- if len(skin_id) == 1:
- num_str = '00' + skin_id
- elif len(skin_id) == 2:
- num_str = '0' + skin_id
- pic_url = "http://ossweb-img.qq.com/images/lol/web201310/skin/big" + hero_id + num_str +".jpg"
- pic_url_list.append(pic_url)
- # 设置文件名称
- path = "D://lol/"
- path_file_list = []
- for pic_name in js_dict.values():
- for skin_id in range(20):
- skin_id = str(skin_id)
- if len(skin_id) == 1:
- num_str = '00' + skin_id
- elif len(skin_id) == 2:
- num_str = '0' + skin_id
- path_file = path + pic_name + num_str + ".jpg"
- path_file_list.append(path_file)
- # 下载
- n = 0
- for dl_url in pic_url_list:
- # n += 1
- res = requests.get(dl_url)
- if res.status_code == 200:
- print("正在下载{}".format(path_file_list[n]))
- with open(path_file_list[n], "wb") as f:
- f.write(res.content)
- n += 1
- if __name__ == '__main__':
- getLOLImages()
Python爬取LOL英雄皮肤的更多相关文章
- Python3爬虫使用requests爬取lol英雄皮肤
本人博客:https://xiaoxiablogs.top 此次爬取lol英雄皮肤一共有两个版本,分别是多线程版本和非多线程版本. 多线程版本 # !/usr/bin/env python # -*- ...
- Python爬取 | 王者荣耀英雄皮肤海报
这里只展示代码,具体介绍请点击下方链接. Python爬取 | 王者荣耀英雄皮肤海报 import requests import re import os import time import wi ...
- 利用python爬取王者荣耀英雄皮肤图片
前两天看到同学用python爬下来LOL的皮肤图片,感觉挺有趣的,我也想试试,于是决定来爬一爬王者荣耀的英雄和皮肤图片. 首先,我们找到王者的官网http://pvp.qq.com/web201605 ...
- Python 爬取所有51VOA网站的Learn a words文本及mp3音频
Python 爬取所有51VOA网站的Learn a words文本及mp3音频 #!/usr/bin/env python # -*- coding: utf-8 -*- #Python 爬取所有5 ...
- python爬取网站数据
开学前接了一个任务,内容是从网上爬取特定属性的数据.正好之前学了python,练练手. 编码问题 因为涉及到中文,所以必然地涉及到了编码的问题,这一次借这个机会算是彻底搞清楚了. 问题要从文字的编码讲 ...
- python爬取某个网页的图片-如百度贴吧
python爬取某个网页的图片-如百度贴吧 作者:vpoet mail:vpoet_sir@163.com 注:随意copy,不用告诉我 #coding:utf-8 import urllib imp ...
- Python:爬取乌云厂商列表,使用BeautifulSoup解析
在SSS论坛看到有人写的Python爬取乌云厂商,想练一下手,就照着重新写了一遍 原帖:http://bbs.sssie.com/thread-965-1-1.html #coding:utf- im ...
- 使用python爬取MedSci上的期刊信息
使用python爬取medsci上的期刊信息,通过设定条件,然后获取相应的期刊的的影响因子排名,期刊名称,英文全称和影响因子.主要过程如下: 首先,通过分析网站http://www.medsci.cn ...
- python爬取免费优质IP归属地查询接口
python爬取免费优质IP归属地查询接口 具体不表,我今天要做的工作就是: 需要将数据库中大量ip查询出起归属地 刚开始感觉好简单啊,毕竟只需要从百度找个免费接口然后来个python脚本跑一晚上就o ...
随机推荐
- pcl point merge
http://pointclouds.org/documentation/tutorials/pairwise_incremental_registration.php#pairwise-increm ...
- [Schema] I have updated my XML Schema for my service but SoapUI still generates/validates according to the old schema.
SoapUI caches XML schemas when they are first loaded. If you need to force a reload of an interfaces ...
- Log4j配置(转)
原文:http://www.blogjava.net/zJun/archive/2006/06/28/55511.html Log4J的配置文件(Configuration File)就是用来设置记录 ...
- Qt的QPixmap半透明
QPixmap pix1(":/PixmapTest/Resources/Chrysanthemum.jpg"); QPixmap temp(pix1.size()); temp. ...
- mybatis 简单实现 left join
sql -- 表a ta (id,aname,bid) -- 表b tb (id,bname) SELECT T1.*, T2.BNAME FROM TA T1 LEFT JOIN TB T2 ON ...
- 获取cpu频率的代码
taskset是linux自带的一个命令,可用来将进程绑定到指定CPU 相关的函数有: sched_setaffinity, CPU_CLR, CPU_ISSET, CPU_SET, CPU_ZERO ...
- 部署图像深度学习Web网站
1. 内网穿透 2. 深度学习Web化 https://www.cnblogs.com/haolujun/p/9778939.html
- Class Loading Deadlocks
By tomas.nilsson on Feb 28, 2010 Mattis keeps going strong, in this installment you get to learn eve ...
- Activity Fragment转场动画
Activity转场动画 先介绍个动画的好例子:https://github.com/lgvalle/Material-Animations Activity的转场动画是通过overridePendi ...
- 2、Semantic-UI之网格布局
2.1 网格布局 在semantic-ui中提供了16个网格,使用class="column",当然也可以通过数字来表示当前网格大小. 在Semantic-UI中定义的网格 ...