primary site for this project: https://tracker.gg/lol
This crawler is built using selenium using the firefox webdriver
In [1]:
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.common.by import By
In [2]:
driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
driver.get("https://tracker.gg/lol/leaderboards/stats/all/LeaguePoints?region=NA&queueType=RANKED_SOLO_5x5")
driver.implicitly_wait(3)
[WDM] - Downloading: 19.0kB [00:00, 2.11MB/s]
In [3]:
na_leaderboard = driver.find_elements(By.TAG_NAME, 'tr')
In [4]:
# python lists to store data
overall_position = []
player_name = []
rank = []
league_points = []
win_rate = []
matches_played = []
In [5]:
for player in na_leaderboard:
new_list = player.text.split()
if len(new_list) == 6:
overall_position.append(new_list[0])
player_name.append(new_list[1])
rank.append(new_list[2])
league_points.append(new_list[3])
win_rate.append(new_list[4])
matches_played.append(new_list[5])
elif len(new_list) == 7:
two_name_player = new_list[1] + new_list[2]
overall_position.append(new_list[0])
player_name.append(two_name_player)
rank.append(new_list[3])
league_points.append(new_list[4])
win_rate.append(new_list[5])
matches_played.append(new_list[6])
elif len(new_list) == 8:
three_name_player = new_list[1] + new_list[2] + new_list[3]
overall_position.append(new_list[0])
player_name.append(three_name_player)
rank.append(new_list[4])
league_points.append(new_list[5])
win_rate.append(new_list[6])
matches_played.append(new_list[7])
print(overall_position)
print(player_name)
print(rank)
print(league_points)
print(win_rate)
print(matches_played)
['5', '7', '8', '13', '14', '17', '18', '18', '21', '23', '26', '27', '31', '34', '37', '39', '48', '48', '61', '65', '66', '68', '72', '75', '75', '77', '82', '82', '84', '89', '89', '94', '95', '96'] ['Nim', 'Neo', 'NIKJOJO', 'noinvade', 'Not', 'niewang', 'nathanwemiss', 'NALCS', 'NaCl', 'MónkeyD', 'noones', 'neopets', 'Notorious', 'nodravenday', 'No', 'newbury', 'Nice', 'Ninja', 'Not', 'Nostalgia', 'Never', 'no1care', 'NIGHTMARE', 'Need', 'Niek', 'Nickji', 'navel', 'Mystical', 'NOOB', 'not', 'MySensei', 'Not', 'NanoSpeck', 'NiMama'] ['Chimpsky', 'NanChangGodE', '1', 'pls', 'Hans', 'zii', 'u', 'YI', 'Tim', 'Luffy', 'fault', 'lover', 'Malli', '1', 'Focus', 'park', 'Bunz', 'Doggy', 'Viable', 'Lee', 'Story', 'me', 'BABY', 'Therapy', 'Joel', '18', 'orange', 'Firefly', 'Fredy41OO', 'skip', 'PzZzang', 'aIöne', 'v2', 'Boom'] ['Challenger', 'Grandmaster', 'Grandmaster', 'Grandmaster', 'Grandmaster', 'Grandmaster', 'Grandmaster', 'Grandmaster', 'Grandmaster', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master', 'Master'] ['954', '822', '802', '658', '637', '557', '552', '552', '547', '509', '435', '433', '379', '345', '309', '308', '211', '211', '93', '75', '73', '65', '45', '44', '44', '36', '29', '29', '23', '18', '18', '13', '2', '1'] ['0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%', '0%']
In [6]:
# check if lists are empty
assert (overall_position != []), 'list is empty'
assert (player_name != []), 'list is empty'
assert (rank != []), 'list is empty'
assert (league_points != []), 'list is empty'
assert (win_rate != []), 'list is empty'
assert (matches_played != []), 'list is empty'
In [7]:
# closing the driver session
driver.quit()
In [8]:
import pandas as pd
In [9]:
# create a dataframe
df = pd.DataFrame({
"overall_position": overall_position,
"player_name": player_name,
"rank": rank,
"league_points": league_points,
"win_rate": win_rate,
"matches_played": matches_played
})
df
Out[9]:
overall_position | player_name | rank | league_points | win_rate | matches_played | |
---|---|---|---|---|---|---|
0 | 5 | Nim | Chimpsky | Challenger | 954 | 0% |
1 | 7 | Neo | NanChangGodE | Grandmaster | 822 | 0% |
2 | 8 | NIKJOJO | 1 | Grandmaster | 802 | 0% |
3 | 13 | noinvade | pls | Grandmaster | 658 | 0% |
4 | 14 | Not | Hans | Grandmaster | 637 | 0% |
5 | 17 | niewang | zii | Grandmaster | 557 | 0% |
6 | 18 | nathanwemiss | u | Grandmaster | 552 | 0% |
7 | 18 | NALCS | YI | Grandmaster | 552 | 0% |
8 | 21 | NaCl | Tim | Grandmaster | 547 | 0% |
9 | 23 | MónkeyD | Luffy | Master | 509 | 0% |
10 | 26 | noones | fault | Master | 435 | 0% |
11 | 27 | neopets | lover | Master | 433 | 0% |
12 | 31 | Notorious | Malli | Master | 379 | 0% |
13 | 34 | nodravenday | 1 | Master | 345 | 0% |
14 | 37 | No | Focus | Master | 309 | 0% |
15 | 39 | newbury | park | Master | 308 | 0% |
16 | 48 | Nice | Bunz | Master | 211 | 0% |
17 | 48 | Ninja | Doggy | Master | 211 | 0% |
18 | 61 | Not | Viable | Master | 93 | 0% |
19 | 65 | Nostalgia | Lee | Master | 75 | 0% |
20 | 66 | Never | Story | Master | 73 | 0% |
21 | 68 | no1care | me | Master | 65 | 0% |
22 | 72 | NIGHTMARE | BABY | Master | 45 | 0% |
23 | 75 | Need | Therapy | Master | 44 | 0% |
24 | 75 | Niek | Joel | Master | 44 | 0% |
25 | 77 | Nickji | 18 | Master | 36 | 0% |
26 | 82 | navel | orange | Master | 29 | 0% |
27 | 82 | Mystical | Firefly | Master | 29 | 0% |
28 | 84 | NOOB | Fredy41OO | Master | 23 | 0% |
29 | 89 | not | skip | Master | 18 | 0% |
30 | 89 | MySensei | PzZzang | Master | 18 | 0% |
31 | 94 | Not | aIöne | Master | 13 | 0% |
32 | 95 | NanoSpeck | v2 | Master | 2 | 0% |
33 | 96 | NiMama | Boom | Master | 1 | 0% |
In [10]:
# create csv file
df.to_csv("na_leaderboard.csv", index=False)
Similar Notebooks
Copyright © Code Fetcher 2022