zoukankan      html  css  js  c++  java
  • Python-下载英雄皮肤

    def hero_skin():
        import json
        import os
        import requests
        from bs4 import BeautifulSoup
    
        headers = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'}
        hero_prefix = 'https://pvp.qq.com/web201605/herodetail/'
        skin_prefix = 'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/'
    
        def get_heroes():
            data_url = 'https://pvp.qq.com/web201605/js/herolist.json'
            r = requests.get(data_url, headers)
            return json.loads(r.text)
    
        def process_hero(hero):
            hero_id = str(hero['ename'])
            hero_name = hero['cname']
            hero_path = os.path.join("皮肤", hero_name)
            if not os.path.isdir(hero_path):   os.mkdir(hero_path)
            hero_url = hero_prefix + hero_id + '.shtml'
            r = requests.get(hero_url, headers)
            text = r.text.encode('iso-8859-1').decode('gbk')
            soup = BeautifulSoup(text, 'lxml')
            skins = soup.select('ul.pic-pf-list.pic-pf-list3')[0].get('data-imgname').split('|')
            for i in range(len(skins)):
                # 页面信息是动态加载出来得,不能直接提取,需要拼装(下载大图)
                img_url = skin_prefix + hero_id + '/' + hero_id + '-bigskin-' + str(i + 1) + '.jpg'
                r = requests.get(img_url, headers)
                with open(hero_path + '/' + skins[i] + '.jpg', 'wb+') as f:
                    f.write(r.content)
            print(hero_name + '' + str(len(skins)) + '张皮肤')
    
    
        for hero in get_heroes():
            process_hero(hero)
    
    hero_skin()
  • 相关阅读:
    BurpSuite—-Spider模块(蜘蛛爬行)
    BurpSuite系列(一)----Proxy模块(代理模块)
    hadoop HA集群搭建步骤
    HBase详解
    MapReduce两种执行环境介绍:本地测试环境,服务器环境
    HBase性能优化方法总结
    HDFS原理解析
    ZooKeeper 典型应用场景
    Redis总结
    基于Apache Curator框架的ZooKeeper使用详解
  • 原文地址:https://www.cnblogs.com/zhouzetian/p/12923360.html
Copyright © 2011-2022 走看看