1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 爬虫英雄联盟官网的全英雄介绍和技能介绍

爬虫英雄联盟官网的全英雄介绍和技能介绍

时间:2020-08-16 15:47:42

相关推荐

爬虫英雄联盟官网的全英雄介绍和技能介绍

import reimport pandas as pdimport 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=1while i <=202:try:html=requests.get('/images/lol/act/img/js/hero/'+str(i)+'.js')s = html.text.encode('utf-8').decode('unicode_escape')# 去除皮肤描述,避免解析json出错双引号乱用的问题pattern = pile(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 paspas0=json1['spells'][1]['name']pas1=json1['spells'][1]['description']# 技能2 qq0=json1['spells'][2]['name']q1=json1['spells'][2]['description']# 技能3 ww0=json1['spells'][4]['name']w1=json1['spells'][4]['description']# 技能4 ee0=json1['spells'][0]['name']e1=json1['spells'][0]['description']# 技能5 rr0=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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。