#爬取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全皮肤原画保存到本地的实例的更多相关文章

  1. python爬取某个网站的图片并保存到本地

    python爬取某个网站的图片并保存到本地 #coding:utf- import urllib import re import sys reload(sys) sys.setdefaultenco ...

  2. 爬取博主所有文章并保存到本地(.txt版)--python3.6

    闲话: 一位前辈告诉我大学期间要好好维护自己的博客,在博客园发布很好,但是自己最好也保留一个备份. 正好最近在学习python,刚刚从py2转到py3,还有点不是很习惯,正想着多练习,于是萌生了这个想 ...

  3. 如何优雅的爬取 gzip 格式的页面并保存在本地(java实现)

    1. 引言 在爬取汽车销量数据时需要爬取 html 保存在本地后再做分析,由于一些页面的 gzip 编码格式, 获取后要先解压缩,否则看到的是一片乱码.在网络上仔细搜索了下,终于在这里找到了一个优雅的 ...

  4. Python爬取LOL英雄皮肤

    Python爬取LOL英雄皮肤 Python 爬虫  一 实现分析 在官网上找到英雄皮肤的真实链接,查看多个后发现前缀相同,后面对应为英雄的ID和皮肤的ID,皮肤的ID从00开始顺序递增,而英雄ID跟 ...

  5. Python3爬虫使用requests爬取lol英雄皮肤

    本人博客:https://xiaoxiablogs.top 此次爬取lol英雄皮肤一共有两个版本,分别是多线程版本和非多线程版本. 多线程版本 # !/usr/bin/env python # -*- ...

  6. python网络图片爬取存储全代码

    #图片爬取全代码import requestsimport osurl = "https://timgsa.baidu.com/timg?image&quality=80&s ...

  7. 爬取表格类网站数据并保存为excel文件

    本文转载自以下网站:50 行代码爬取东方财富网上市公司 10 年近百万行财务报表数据 https://www.makcyun.top/web_scraping_withpython6.html 主要学 ...

  8. 使用Python爬取微信公众号文章并保存为PDF文件(解决图片不显示的问题)

    前言 第一次写博客,主要内容是爬取微信公众号的文章,将文章以PDF格式保存在本地. 爬取微信公众号文章(使用wechatsogou) 1.安装 pip install wechatsogou --up ...

  9. scrapy框架来爬取壁纸网站并将图片下载到本地文件中

    首先需要确定要爬取的内容,所以第一步就应该是要确定要爬的字段: 首先去items中确定要爬的内容 class MeizhuoItem(scrapy.Item): # define the fields ...

随机推荐

  1. 《C语言深度解剖》学习笔记之预处理

    第3章 预处理 1.下面两行代码都是错的.因为注释先于预处理指令被处理,当这两行被展开成“//……”和“/*……*/”时,注释已处理完毕,所以出现错误 #define BSC // #define B ...

  2. matplotlib绘制热力图

    版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/jin_tmac/article/deta ...

  3. TCP/IP 、HTTP和SOCKET

    TCP/IP协议概念 TCP/IP(Transmission Control Protocol/Internet Protocol)的简写,中文译名为传输控制协议/因特网互联协议,又叫网络通讯协议,这 ...

  4. Python深入:修改Python搜索路径

    当Python执行import语句时,它会在一些路径中搜索Python模块和扩展模块.可以通过sys.path查看这些路径,比如: >>> import sys >>&g ...

  5. hdu 3873 Invade the Mars(有限制的最短路 spfa+容器)

    Invade the Mars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 365768/165536 K (Java/Others ...

  6. C. Tokitsukaze and Duel 前缀维护

    枚举每一个连续的K的第一个位置,如果是先手胜利,那么前[1 , i-1 ]和[ i+k , n ]区间要么全是0,要么全是1 如果能够平局,那么肯定是[1,i-1],以及[ i+k , n]中有两种情 ...

  7. spark sql thrift server

    ### create data ## cat ## echo "$(date ;echo ## cat }'";exit}' ..} do passwd) echo "$ ...

  8. hdu 1050 Moving Tables (Greedy)

    Problem - 1050 过两天要给12的讲贪心,于是就做一下水贪心练习练习. 代码如下: #include <cstdio> #include <iostream> #i ...

  9. kindeditor编辑器微软雅黑样式font-family值变成&quot;

    http://www.100cm.cn/article-126-764.html kindeditor编辑器中选中文字, 修改字体(字体名称中带有空格, 例如"Microsoft YaHei ...

  10. H3C OSPF协议区域LSA发布