记一次 爬取LOL全皮肤原画保存到本地的实例
#爬取lol全英雄皮肤
import re
import traceback # 异常跟踪
import requests
from bs4 import BeautifulSoup
#获取html
def get_url(url, hander):
try:
r = requests.get(url, headers=hander, timeout=30)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
traceback.print_exc() #将异常信息打印出来
return ""
#解析html
def prasing_page(lst,html):
try:
soup = BeautifulSoup(html, "html.parser")
for a in soup.find_all('li', class_=re.compile('boxShadow')):
tag_a = a('a')
for i in tag_a:
lst.append(i['href'])
return lst
except:
traceback.print_exc()
return ""
#解析获取到的单个html并筛选和下载
def getUrl_prasingpag(lst, hander):
hero_img_url = []
hero_skin_name = []
hero_name = []
for u in lst:
try:
r = requests.get(u, headers=hander, timeout=30)
r.raise_for_status()
r.encoding = r.apparent_encoding
#二次解析
soup = BeautifulSoup(r.text, "html.parser")
pag = soup.find_all('div', class_=re.compile('othersPifuBox'))
for m in pag:
tag_img = m('img')
tag_p = m('p')
tag_span = m('span')
for m in tag_p:
hero_skin_name.append(m.string)
for m in tag_img:
hero_img_url.append(m['src'])
for m in tag_span:
hero_name.append(m.string)
except:
traceback.print_exc() # 将异常信息打印出来
continue
#下载到本地
for i in range(len(hero_name)):
try:
path = 'O:/lol_hero_jpg/' + hero_skin_name[i]+'--' + hero_name[i] + '.jpg'
f = open(path, 'wb')
r = requests.get(hero_img_url[i], stream=True)
f.write(r.content)
print("\r当前进度>>>>>>>>>>>>>>>>>>{:.0f}%>>>>>>>>>>>>>>>>>>".format(i * 100 / len(lst)), end="")
f.close()
except:
traceback.print_exc() # 将异常信息打印出来
continue
def main():
hander = {"User-Agent":"Mozilla/5.0"}
deep = 43 #定义爬取页数
list = []
for i in range(deep):
try:
url = "http://********/hero_"+str(1+i)+".shtml"
html = get_url(url, hander)
prasing_page(list, html)
getUrl_prasingpag(list, hander)
except:
continue
main()
记一次 爬取LOL全皮肤原画保存到本地的实例的更多相关文章
- python爬取某个网站的图片并保存到本地
python爬取某个网站的图片并保存到本地 #coding:utf- import urllib import re import sys reload(sys) sys.setdefaultenco ...
- 爬取博主所有文章并保存到本地(.txt版)--python3.6
闲话: 一位前辈告诉我大学期间要好好维护自己的博客,在博客园发布很好,但是自己最好也保留一个备份. 正好最近在学习python,刚刚从py2转到py3,还有点不是很习惯,正想着多练习,于是萌生了这个想 ...
- 如何优雅的爬取 gzip 格式的页面并保存在本地(java实现)
1. 引言 在爬取汽车销量数据时需要爬取 html 保存在本地后再做分析,由于一些页面的 gzip 编码格式, 获取后要先解压缩,否则看到的是一片乱码.在网络上仔细搜索了下,终于在这里找到了一个优雅的 ...
- Python爬取LOL英雄皮肤
Python爬取LOL英雄皮肤 Python 爬虫 一 实现分析 在官网上找到英雄皮肤的真实链接,查看多个后发现前缀相同,后面对应为英雄的ID和皮肤的ID,皮肤的ID从00开始顺序递增,而英雄ID跟 ...
- Python3爬虫使用requests爬取lol英雄皮肤
本人博客:https://xiaoxiablogs.top 此次爬取lol英雄皮肤一共有两个版本,分别是多线程版本和非多线程版本. 多线程版本 # !/usr/bin/env python # -*- ...
- python网络图片爬取存储全代码
#图片爬取全代码import requestsimport osurl = "https://timgsa.baidu.com/timg?image&quality=80&s ...
- 爬取表格类网站数据并保存为excel文件
本文转载自以下网站:50 行代码爬取东方财富网上市公司 10 年近百万行财务报表数据 https://www.makcyun.top/web_scraping_withpython6.html 主要学 ...
- 使用Python爬取微信公众号文章并保存为PDF文件(解决图片不显示的问题)
前言 第一次写博客,主要内容是爬取微信公众号的文章,将文章以PDF格式保存在本地. 爬取微信公众号文章(使用wechatsogou) 1.安装 pip install wechatsogou --up ...
- scrapy框架来爬取壁纸网站并将图片下载到本地文件中
首先需要确定要爬取的内容,所以第一步就应该是要确定要爬的字段: 首先去items中确定要爬的内容 class MeizhuoItem(scrapy.Item): # define the fields ...
随机推荐
- "不用谢" 的11种表达
说Thank you ,机械版的反应you are welcome.虽然没错,但实在太老掉牙,在国外使用率不高: 随性,不足挂齿的小事 Not a problem 别放在心上 Any time 有事随 ...
- 光程科技IOS签名配置
光程科技IOS签名配置,APICloudAPP签名时config配置必须加上: <preference name="appCertificateVerify" value=& ...
- laravel5.6 发送邮件附带邮件时,Unable to open file for reading,报错文件路径问题
https://stackoverflow.com/questions/48568739/unable-to-open-file-for-reading-swift-ioexception-in-la ...
- GPU版TensorFlow怎么指定让CPU运行
由于某些原因GPU版的TensorFlow运行起来会出现一些问题,比如内存溢出等情况.此时我们可以用CPU和系统内存来运行我们的程序. 代码如下: import osos.environ[" ...
- HDU2087 剪花布条 题解 KMP算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2087 题目大意:给定字符串 \(s\) 和 \(t\) ,找出 \(s\) 中出现不重叠的 \(t\) ...
- 【CSS3】精美横向滚动菜单按钮
废话不多说,直接上图: 然后是代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- 深入java面向对象三:抽象类和接口(转载)
文章系转载,地址: http://blog.csdn.net/xw13106209/article/details/6923556 1.概述 一个软件设计的好坏,我想很大程度上取决于它的整体架 ...
- [转]1.2 java web的发展历史
前言 了解java web的发展历史和相关技术的演进历程,非常有助于加深对java web技术的理解和认识. 阅读目录 1.Servlet的出现 2.Jsp的出现 3.倡导了MVC思想的Servlet ...
- Activiti - 新一代的开源 BPM 引擎
http://www.ibm.com/developerworks/cn/Java/j-lo-activiti1/ ****************************************** ...
- Vue的事件修饰符
转载于:https://www.cnblogs.com/xuqp/p/9406971.html 事件处理 如果需要在内联语句处理器中访问原生DOM事件.可以使用特殊变量$event,把它传入到meth ...