admin管理员组文章数量:1619291
- 百度英雄联盟,进入官网,在游戏资料里面找到所有英雄数据
- 在页面F12中network中找到hero_list.js,所有的数据都在这里面,接下来就简单了,直接放上代码
将数据储存到mysql
import requests
import json
import pymysql
url = 'https://game.gtimg/images/lol/act/img/js/heroList/hero_list.js'
conn = pymysql.Connect(host='127.0.0.1', port=3306, db='xtj_1', password='xtj', user='root', charset='utf8')
cursor = conn.cursor()
resp = requests.get(url)
hero_list = json.loads(resp.text)
for i in hero_list['hero']:
# print(i['name'],i['title'])
x = 'https://game.gtimg/images/lol/act/img/champion/' + i['alias'] + '.png'
cursor.execute("insert into hero1(name,title,href) values(%s,%s,%s)", (i['name'], i['title'],x))
connmit()
从mysql中拿出数据,在桌面上新建文件夹并保存图片
import pymysql
import requests
import os
fpath ='e:/desketop/hero/'
conn = pymysql.Connect(host='127.0.0.1',port=3306,user='root',password='xtj',charset='utf8',db='xtj_1')
cursor=conn.cursor()
cursor.execute("select href from hero1")
result =cursor.fetchall()
for i in result:
# print(i[0])
resp=requests.get(i[0])
if not os.path.exists(fpath):
os.mkdir(fpath)
print('创建文件夹')
if not os.path.exists(fpath + i[0].split('/')[-1]):
with open(fpath + i[0].split('/')[-1],'wb') as f:
f.write(resp.content)
print('写入图片中')
else:
print('文件已存在')
最后看下我的结果:
版权声明:本文标题:爬取lol官网所有英雄照片,并存储到pysql 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1728795110a1174090.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论