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

 

本文标签: 英雄爬虫官网技能联盟