7 lines of code teach you to climb [hero alliance official website] in Python: ① master crawler technology; ② Learn Python data visualization

Hello, I'm Mingyue 14th bridge!!

Areas of expertise: python black technology, big data back-end research and development, data warehouse

Today's focus:

① master the crawler technology, experience the python crawler process, and climb when you can see it;

② learn to use python data visualization.

Friends with questions are welcome to comment at the end of the article. Praise and collection are my greatest support!!!
 

catalogue

1, Origin

2, Reptile

3, Drawing analysis

3.1 physical attack

3.2 magic attack

3.3 defense capability

3.4 difficulty coefficient

3.5 # capability matrix

4, All codes

1, Origin

Here's the thing:

Buddy: brother Qiao, brother Qiao, do you know which hero is the hardest to play?

Brother Qiao: lost in thought Although I already have that candidate in my heart, like children Jie and chicken 😋 , But which is the most difficult In the Internet age, we use data to speak. Let's go and see what the official data say...

 

2, Reptile

Step 1:

First of all, brother Qiao came to the official website of the League of heroes. Although he has long been unable to lift the knife, he still can't help but miss his college days~

After observation, you can climb down and analyze the [hero], [item], [Rune], etc..

Step 2:

Q: What are our needs?

A: Find the data on the official website and see which heroes are the most difficult.

 

First, go to the official website > > > Hero League home page』 >>> 『Game materials "> > >" hero "

We've seen all the heroes. Just click and have a look~

It's you, trickster!

Step 3:

1. Open the developer mode, click the arrow on the left and select the element you want to view.

2. Visible data: Hero's [physical attack], [magic attack], [defense ability], [starting difficulty]

Trickster:

Physical attack: ☆

Magic attack: ☆☆☆☆☆☆☆☆☆☆☆☆☆☆

Defense capability: ☆☆☆☆

Difficulty coefficient: ☆☆☆☆☆☆☆☆☆☆☆

ok, that's what I want.

ps. you can also climb all skin, hero background knowledge, Raiders, skill introduction, etc

Step 4: loop traversal

Hero list: https://lol.qq.com/data/info-heros.shtml

 

3, Drawing analysis

3.1 physical attack

The hero with the lowest physical attack (Level 1): the Colossus of justice, the Witch of deception, the fallen angel, the ice crystal Phoenix, the apocalypse, the ancient witch spirit, the Twilight star spirit, the rock bird, and the ten thousand flower channeling


Hero with the highest physical attack (level 10): Wuji sword saint, king of barbarians, night hunter, unparalleled sword Ji, sickle of shadow flow, dramatist, inverse feather

 

3.2 magic attack

Hero with the lowest magic attack (Level 1): goddess of war, night hunter, power of demacia, shadow of blade, blade of exile, honor executioner, hand of Knox, sickle of shadow flow, Lord of shadow flow, counter feather, solemnity of the waning moon, ghost of blood harbor, wrist hero


The highest hero of magic attack (level 10): the daughter of darkness, the Witch of deception, the rune mage, the death chanter, the ice crystal Phoenix, the evil little mage, the ancient witch spirit, the mechanical pioneer, the eye of void, and the shy bud

 

3.3 defense capability

Heroes with the lowest defense ability (Level 1): night hunter, magic cat, Wanhua channeling


Hero with the highest defense ability (level 10): giant statue of justice, armored dragon turtle

 

 

3.4 difficulty coefficient

Hero with the lowest difficulty coefficient (Level 1): night hunter, magic cat, Wanhua channeling


Hero with the highest difficulty coefficient (level 10): giant statue of justice, armored dragon turtle

 

3.5 # capability matrix

ps. take Annie and Kalma as examples!

4, All codes

# encoding: utf-8
import requests
import json
from pyecharts.charts import Pie
from pyecharts import options as opts
from pyecharts.charts import Radar

# Get hero data on the official website
def request(url):
    headers = { "User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3)",}
    res = requests.get(url, headers=headers)
    return res

def data_analysis(title,data):
    res = {}
    for hero in data:
        if hero['%s'%title] not in res:
            res[hero['%s'%title]] = hero['name']
        else:
            res[hero['%s'%title]] = res[hero['%s'%title]] + "," + hero['name']
    print(res)
    return res

def draw_pie(title, attack):
    columns,data = [],[]
    for k, v in attack.items():
        columns.append(title + k + 'level')
        data.append(len(v.split(',')))
        if k in ['1','10']:
            print(k,v)
    pie = (
        Pie()
            # With [(label, value), (label, value), (label, value)...] Form incoming data.
            .add(title, list(z for z in zip(columns, data)))
            .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
    )
    pie.render('%s.html'%title)


def draw_Radar():
    from pyecharts.charts import Radar
    radar = Radar()
    # //Since the incoming data of radar chart must be multidimensional data, it needs to be processed here
    radar_data = [[10, 10, 10, 10, 10]]
    radar_data1 = [[2, 10, 3, 6, 3]]
    radar_data2 = [[1, 8, 7, 5, 8]]

    # //Set the maximum value of column. In order to make the radar chart more intuitive, the monthly maximum value setting here is different
    schema = [
        ("Physics", 100), ("magic", 10), ("defense", 10),("difficulty", 10),("like", 10)
    ]
    # //Incoming coordinates
    radar.add_schema(schema)
    radar.add("Full mark", radar_data)
    # //Generally, the same color is used by default. Here, in order to make it easy to distinguish, you need to set the color of item
    radar.add("Annie", radar_data1, color="#E37911")
    radar.add("kalmar ", radar_data2, color="#1C86EE")
    radar.render()

if __name__ == '__main__':
    url = "https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js"
    res = request(url)
    hero_message = json.loads(res.text)['hero']
    # print(hero_message)

    # Physics
    attack = data_analysis('attack', hero_message)
    draw_pie('Physics', attack)

    # defense
    defense = data_analysis('defense', hero_message)
    draw_pie('defense', defense)

    # magic
    magic = data_analysis('magic', hero_message)
    draw_pie('magic', magic)

    # difficulty
    difficulty = data_analysis('difficulty', hero_message)
    draw_pie('difficulty', difficulty)

    draw_Radar()


 

  

CSDN official learning recommendation ↓↓

In order to help more Xiaobai advance from zero, a set of Atlas of Python engineers' learning and growth knowledge was obtained from CSDN officials, with a size of 870mm x 560mm. After unfolding, it is the size of a desk, which can also be folded into the size of a book.

Interested friends can learn that the blogger's articles are always free anyway~

 

[recommended reading]

Data warehouse column: data warehouse methodology, practical experience, real interview questions > > https://blog.csdn.net/weixin_39032019/category_8871528.html

Python column: Python black Technology: crawlers, algorithms, gadgets > > https://blog.csdn.net/weixin_39032019/category_8974792.html

Big data collection column: real interview questions, development experience and tuning strategies > > https://blog.csdn.net/weixin_39032019/category_11048805.html

 

I'm brother Qiao, who focuses on sharing big data knowledge system & Python black technology.

Ask for praise, comment and collection!!

Keywords: Python

Added by bruceg on Mon, 31 Jan 2022 08:15:36 +0200