import re
import time
import requests
from bs4 import BeautifulSoup
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
}
result = []
for i in range(1, 82):
    url = f"https://kumamate.net/data/?mode=rate&fighter={i}"
    r = requests.get(url, headers=headers)
    r.raise_for_status()
    soup = BeautifulSoup(r.content, "html.parser")
    for trs in soup.find_all("tr", class_=re.compile("RecentMatch[12]")):
        tds = trs.find_all("td")
        win, lose, _ = re.split("[Win or lose]", tds[3].get_text(strip=True))
        data = [
            tds[0].img.get("alt"),
            tds[2].get_text(strip=True),
            int(win),
            int(lose),
            float(tds[4].get_text(strip=True).rstrip("%")),
        ]
        result.append(data)
    time.sleep(1)
result
import pandas as pd
df = pd.DataFrame(result, columns=["myself", "Opponent", "Win", "Loss", "Win率"])
#Number of uses calculation
df["Number of uses"] = df["Win"] + df["Loss"]
#Total number of uses by fighter
pv = df.pivot_table(values="Number of uses", index="myself", aggfunc="sum").reset_index()
pv.rename(columns={"myself": "Opponent", "Number of uses": "Registration number"}, inplace=True)
df1 = pd.merge(df, pv, on="Opponent")
#VIP calculation
df1["VIP"] = df1["Registration number"] * df1["Win rate"]
#Exclude the same character
df2 = df1[df1["myself"] != df1["Opponent"]].copy()
#VIP aggregation by fighter
pv1 = df2.pivot_table(values="VIP", index="myself", aggfunc="sum").sort_values(
    by="VIP", ascending=False
)
pv1["VIP"] = (pv1["VIP"] // 100000).astype(int)
print(pv1.to_markdown())
| myself | Number of uses | |
|---|---|---|
| 1 | Ganondorf | 24004 | 
| 2 | Joker | 19527 | 
| 3 | Bowser | 19016 | 
| 4 | Mario | 17186 | 
| 5 | Donkey Kong | 15838 | 
| 6 | Lucina | 15771 | 
| 7 | Pudding | 13148 | 
| 8 | Lucas | 12628 | 
| 9 | Cloud | 12264 | 
| 10 | Roy | 11374 | 
| 11 | Zelda | 11125 | 
| 12 | Captain Falcon | 11044 | 
| 13 | Beleth / Beleth | 10269 | 
| 14 | Palutena | 10159 | 
| 15 | Mars | 10126 | 
| 16 | Kirby | 9388 | 
| 17 | Link | 9173 | 
| 18 | Incineroar | 8657 | 
| 19 | Falco | 8223 | 
| 20 | Ness | 8061 | 
| 21 | robot | 8032 | 
| 22 | Ink ring | 7986 | 
| 23 | Terry | 7955 | 
| 24 | Wolf | 7867 | 
| 25 | Pikachu | 7739 | 
| 26 | snake | 7330 | 
| 27 | Yoshi | 7275 | 
| 28 | Greninja | 6898 | 
| 29 | Ike | 6333 | 
| 30 | Mr.game&watch | 6333 | 
| 31 | Meen Meen | 6290 | 
| 32 | Bayonetta | 6286 | 
| 33 | Dedede | 6201 | 
| 34 | Fox | 6198 | 
| 35 | Ken | 6088 | 
| 36 | Brave | 6077 | 
| 37 | Mewtwo | 6037 | 
| 38 | Rufure | 5917 | 
| 39 | King Kruul | 5893 | 
| 40 | Zero Suit Samus | 5454 | 
| 41 | Kamui | 5453 | 
| 42 | Ridley | 5446 | 
| 43 | Pac-Man | 5262 | 
| 44 | Pokemon trainer | 5093 | 
| 45 | Pakkun Flower | 5019 | 
| 46 | Samus | 4854 | 
| 47 | Black pit | 4733 | 
| 48 | Dark samus | 4716 | 
| 49 | Wii Fit trainer | 4693 | 
| 50 | chromium | 4630 | 
| 51 | Dr. Mario | 4405 | 
| 52 | Murabito | 4261 | 
| 53 | Shulk | 4201 | 
| 54 | Meta Knight | 4173 | 
| 55 | seek | 4127 | 
| 56 | Luigi | 4103 | 
| 57 | Bowser.Jr | 3974 | 
| 58 | Pichu | 3886 | 
| 59 | banjo&Kazooie | 3867 | 
| 60 | Little mac | 3818 | 
| 61 | Children's link | 3653 | 
| 62 | Duck hunt | 3282 | 
| 63 | Isabelle | 3208 | 
| 64 | Lucario | 3167 | 
| 65 | Rockman | 3073 | 
| 66 | Toon link | 2954 | 
| 67 | Sonic | 2848 | 
| 68 | Wario | 2506 | 
| 69 | Pikmin&Olimar | 2340 | 
| 70 | Ice climber | 2324 | 
| 71 | pit | 2265 | 
| 72 | Fighting Mii | 2262 | 
| 73 | Peach | 2251 | 
| 74 | Rosetta&Chico | 2192 | 
| 75 | Shooting Mii | 2169 | 
| 76 | Ryu | 2151 | 
| 77 | Daisy | 1880 | 
| 78 | Diddy Kong | 1829 | 
| 79 | Simon | 1554 | 
| 80 | Richter | 1515 | 
| 81 | Swordsman Mii | 1383 | 
| myself | VIP | 
|---|---|
| Bowser.Jr | 303 | 
| banjo&Kazooie | 300 | 
| Richter | 299 | 
| Meen Meen | 296 | 
| Shooting Mii | 295 | 
| Duck hunt | 291 | 
| Fox | 287 | 
| Rufure | 285 | 
| Fighting Mii | 284 | 
| Rockman | 284 | 
| Incineroar | 283 | 
| Mr.game&watch | 282 | 
| Ken | 281 | 
| Dedede | 278 | 
| Swordsman Mii | 277 | 
| Greninja | 276 | 
| Dark samus | 276 | 
| Bayonetta | 275 | 
| snake | 274 | 
| Toon link | 274 | 
| Black pit | 274 | 
| Simon | 273 | 
| Falco | 273 | 
| Pakkun Flower | 273 | 
| Diddy Kong | 273 | 
| Wii Fit trainer | 272 | 
| Meta Knight | 272 | 
| Peach | 272 | 
| Samus | 268 | 
| Zelda | 268 | 
| Ike | 268 | 
| Pikmin&Olimar | 267 | 
| pit | 267 | 
| robot | 266 | 
| Ryu | 266 | 
| Pac-Man | 266 | 
| Ice climber | 266 | 
| Rosetta&Chico | 265 | 
| Palutena | 265 | 
| Murabito | 265 | 
| Brave | 264 | 
| Dr. Mario | 264 | 
| Pokemon trainer | 264 | 
| Daisy | 262 | 
| Link | 261 | 
| Pichu | 260 | 
| Mario | 260 | 
| chromium | 260 | 
| Kamui | 259 | 
| Yoshi | 259 | 
| King Kruul | 258 | 
| Wolf | 258 | 
| Little mac | 258 | 
| Lucario | 258 | 
| Wario | 257 | 
| Shulk | 257 | 
| Ink ring | 257 | 
| Cloud | 257 | 
| Roy | 256 | 
| Children's link | 256 | 
| Pikachu | 256 | 
| Bowser | 256 | 
| Mewtwo | 256 | 
| Luigi | 255 | 
| Terry | 255 | 
| Sonic | 255 | 
| Ness | 254 | 
| seek | 254 | 
| Isabelle | 253 | 
| Lucas | 252 | 
| Captain Falcon | 250 | 
| Pudding | 250 | 
| Donkey Kong | 249 | 
| Mars | 249 | 
| Lucina | 248 | 
| Zero Suit Samus | 246 | 
| Ridley | 245 | 
| Joker | 244 | 
| Kirby | 244 | 
| Beleth / Beleth | 241 | 
| Ganondorf | 240 | 
[First scraping] I tried to make a VIP character for Smash Bros. [Beautiful Soup] [Data analysis]
Recommended Posts