#爬取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. 8-2udp和tcp网络编程以及粘包和解决粘包的方法

    一  tcp网络编程 server 端 import socket sk=socket.socket() #实例化一个对象 sk.setsockopt(socket.SOL_SOCKET,socket ...

  2. less的引入和使用

    文章地址:https://www.cnblogs.com/sandraryan/ 之前就了解过less,但项目一直用的是css,所以,重新做一次系统的了解,顺便写个博客Orz 简介 less和sass ...

  3. tp3.2.3 解决http://lx.com/后必须加index.php才能访问的问题,配置文件中忘了加index index.php index.html 等默认文件

    server { listen 80; server_name lx.com; root "D:\phpstudy\PHPTutorial\WWW\liuxue"; locatio ...

  4. jar包运行

    配置mainClass:            <plugin>                <groupId>org.apache.maven.plugins</gr ...

  5. 什么是响应式设计?响应式设计的基本原理是什么?如何兼容低版本的 IE?

    响应式网站设计(Responsive Web design)的理念是:集中创建页面的图片排版大小,可以智能地根据用户行为以及 使用的设备环境(系统平台.屏幕尺寸.屏幕定向等)进行相对应的布局,无论用户 ...

  6. 2018-8-10-win10-sdk-是否向下兼容

    title author date CreateTime categories win10 sdk 是否向下兼容 lindexi 2018-08-10 19:16:53 +0800 2018-2-13 ...

  7. dotnet 设计规范 · 结构体定义

    X 不要给结构体默认构造函数 默认的C#编译器也不让开发者定义有默认构造的结构体 X 不要定义易变的属性 易变的属性指的是在调用属性返回值的时候返回的是新的实例,易变的属性会有很多的问题. ✓ 需要确 ...

  8. Python--day40--全局解释器锁

    1,起一百个线程和起一百个进程所花的时间对比(开启效率的较量): import time from threading import Thread from multiprocessing impor ...

  9. H3C RIP可选配置

  10. Pandas库之DataFrame

    Pandas库之DataFrame 1 简介 DataFrame是Python中Pandas库中的一种数据结构,它类似excel,是一种二维表. 或许说它可能有点像matlab的矩阵,但是matlab ...