admin管理员组文章数量:1619183
import re
import pandas as pd
import requests
# 循环了
cols=['heroId','name','alias','title','roles','shortBio','attack','defense','magic','hp','hpperlevel','mp','mpperlevel','armor','spellblock',
'attackdamage','attackdamageperlevel','pas0','pas1','q0','q1','w0','w1','e0','e1','r0','r1']
data = pd.DataFrame(columns=cols)
i=1
while i <=202:
try:
html=requests.get('https://game.gtimg/images/lol/act/img/js/hero/'+str(i)+'.js')
s = html.text.encode('utf-8').decode('unicode_escape')
# 去除皮肤描述,避免解析json出错双引号乱用的问题
pattern = repile(r'"skins":(.*?)"spells"',re.S)
result1 = pattern.findall(s)[0]
s=s.replace(result1,'"",')
json1 = json.loads(s, strict=False)
# 记录基本信息
heroId=json1['hero']["heroId"]
name=json1['hero']["name"]
alias=json1['hero']["alias"]
title=json1['hero']["title"]
roles=json1['hero']["roles"]
shortBio=json1['hero']["shortBio"]
attack=json1['hero']["attack"]
defense=json1['hero']["defense"]
magic=json1['hero']["magic"]
hp=json1['hero']["hp"]
hpperlevel=json1['hero']["hpperlevel"]
mp=json1['hero']["mp"]
mpperlevel=json1['hero']["mpperlevel"]
armor=json1['hero']['armor']
spellblock=json1['hero']['spellblock']
# 攻击力
attackdamage=json1['hero']['attackdamage']
# 攻击成长
attackdamageperlevel=json1['hero']['attackdamageperlevel']
# 技能1 pas
pas0=json1['spells'][1]['name']
pas1=json1['spells'][1]['description']
# 技能2 q
q0=json1['spells'][2]['name']
q1=json1['spells'][2]['description']
# 技能3 w
w0=json1['spells'][4]['name']
w1=json1['spells'][4]['description']
# 技能4 e
e0=json1['spells'][0]['name']
e1=json1['spells'][0]['description']
# 技能5 r
r0=json1['spells'][3]['name']
r1=json1['spells'][3]['description']
# 执行写入
data.loc[len(data)]=[
heroId,name,alias,title,roles,shortBio,attack,defense,magic,hp,hpperlevel,mp,mpperlevel,armor,spellblock,
attackdamage,attackdamageperlevel,pas0,pas1,q0,q1,w0,w1,e0,e1,r0,r1]
except:
print ('出错'+str(i))
i+=1
版权声明:本文标题:爬虫英雄联盟官网的全英雄介绍和技能介绍 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1728792699a1173865.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论