python爬取LOL英雄皮肤
2020-07-14 04:44
357 查看
我的博客:https://justlovesmile.top
- 编写爬虫获取英雄联盟所有英雄的全部皮肤
- 需要库:
- requests
- re
- json
- os
- 效果:在该代码文件目录下生成n个Hero文件夹保存皮肤图片。
""" Date: 2019.11.7 Author: Justlovesmile Language: python3 """ import requests import re import json import os def getHtml(url): try: r=requests.get(url) r.raise_for_status() r.encoding=r.apparent_encoding except: print(url+"爬取失败!") else: response = r.text getInfo(response) def getInfo(res): lists=re.findall(r'"keys":(.*?),"data"',res) #print(lists) hero_id=json.loads(lists[0]) #print(hero_id) for hero in hero_id.values(): getSkin(hero) def getSkin(hero): url='https://lol.qq.com/biz/hero/'+hero+'.js' try: r=requests.get(url) r.raise_for_status() r.encoding=r.apparent_encoding except: print(url+"爬取失败!") else: html=r.text num=re.findall(r'"id":"(\d{4,6})","num"',html) for i in range(len(num)): img_url='https://game.gtimg.cn/images/lol/act/img/skin/big' + num[i] + '.jpg' save_img(hero,img_url) def save_img(hero,img_url): root=hero+"\\" path=root+img_url.split('/')[-1] try: if not os.path.exists(root): os.mkdir(root) if not os.path.exists(path): r=requests.get(img_url) with open(path,'wb') as f: f.write(r.content) f.close() print("文件保存成功!") else: print("文件已存在!") except: print("爬取失败!") print(img_url+"已下载") def main(): url="https://lol.qq.com/biz/hero/champion.js" getHtml(url) if __name__ == "__main__": main()
相关文章推荐
- Python练手项目:20行爬取全王者全英雄皮肤
- 用Python爬取"王者农药"英雄皮肤
- python3.5爬取王者荣耀官网所有英雄的皮肤
- java使用io流技术替换LOL英雄的皮肤
- 20行Python代码爬取王者荣耀全英雄皮肤
- 20行Python代码爬取王者荣耀全英雄皮肤
- Python爬取英雄联盟英雄皮肤
- 用python的requests第三方模块抓取王者荣耀所有英雄的皮肤实例
- 用Python爬取"王者农药"英雄皮肤
- 【Python应用】爬取LOL皮肤图片(面向过程编程)
- 王者荣耀英雄全皮肤4K高清大图,python爬虫帮你保存下来
- Python带你爬取LOL皮肤美图,形成视觉盛宴
- python爬虫——爬取王者荣耀全英雄皮肤
- Python3爬取英雄联盟英雄皮肤大图实例代码
- python爬虫入门------王者荣耀英雄及皮肤数据爬取项目
- LOL全英雄皮肤爬虫
- Python——多线程爬取英雄联盟官网内所有的英雄皮肤,按名字分类下载到本地
- 用Python爬取"农药"英雄皮肤
- 20行 Python 代码爬取王者荣耀全英雄皮肤 | 原力计划
- python实践——《英雄联盟》英雄及皮肤图片的爬虫