• Python 爬取LOL英雄壁纸


    直接上代码

    ###导入模块
    import requests
    from lxml import etree
    import requests,json
    import sys
    import difflib
    import os
    header={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'}
    # https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js 英雄列表
    url='https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js'
    
    # 文件夹不存在则创建
    save_dir = 'LOLHeroSkin'
    if not os.path.exists(save_dir):
        os.mkdir(save_dir)
    
    heros=json.loads(requests.get(url,headers=header).content)['hero']
    for hero in heros:
        id=int(hero['heroId'])
        url='https://game.gtimg.cn/images/lol/act/img/js/hero/'+str(id)+'.js'
        skins=json.loads(requests.get(url,headers=header).content)['skins']
        for skin in skins:
            name=skin['name'].replace('/','_').replace('“','_').replace('”','_').replace(':','_').replace('"','_')
            imgUrl=skin['mainImg']
            if imgUrl=='': # 炫彩图片
                continue
            img=requests.get(imgUrl,header)
            with open(save_dir+'/'+name+'.jpg',"wb") as file:
                file.write(img.content)
            print(name+'.jpg  下载成功')
    
    
    print("OK")
    
  • 相关阅读:
    015-面向对象
    017-错误和异常
    019-File
    020-OS
    021-模块
    022-标准库
    数据库目录
    数据库 概念详解
    MySQL 基础
    MySQL 数据库操作
  • 原文地址:https://www.cnblogs.com/Alex-Mercer/p/13404118.html
Copyright © 2020-2023  润新知