Convoy [#9]
how the fuck did you scrap the information
Yeahhhhhhhhh you got me thinking with this comment, just coded it. Was pretty fun
The below code gives me these all time avg stats for flor though:
{'player_name': 'florescent', 'rnd': 451, 'rating': 1.5, 'acs': 284.03, 'kd': 1.9, 'adr': 184.59, 'kast': 81, 'kpr': 1.03, 'apr': 0.38, 'fkpr': 0.11, 'fdpr': 0.07, 'k': 463, 'd': 302, 'a': 99, 'fk': 90, 'fd': 52}
import requests
from bs4 import BeautifulSoup
player_stats_template = {
"player_name": "", # Player's name
"rnd": 0, # Number of rounds played
"rating": 0.0, # Player rating
"acs": 0.0, # Average combat score
"kd": 0.0, # Kill/Death ratio
"adr": 0.0, # Average damage per round
"kast": 0, # Kill, Assist, Survive, or Traded percentage
"kpr": 0.0, # Kills per round
"apr": 0.0, # Assists per round
"fkpr": 0.0, # First kills per round
"fdpr": 0.0, # First deaths per round
"k": 0, # Total kills
"d": 0, # Total deaths
"a": 0, # Total assists
"fk": 0, # Total first kills
"fd": 0 # Total first deaths
}
TOTAL_MAX_PLAYERS = 48850 # total number of players on vlr to potentially scrape
def get_player_data(player_num):
url = f"https://www.vlr.gg/player/{player_num}/?timespan=all"
response = requests.get(url)
if response.status_code != 200:
return None
soup = BeautifulSoup(response.content, 'html.parser')
# player name ^-^
player_name_tag = soup.find('h1', class_='wf-title')
player_name = player_name_tag.text.strip() if player_name_tag else player_num
player_stats_template["player_name"] = player_name
accumulator = {key: 0 for key in player_stats_template if key != "player_name"}
num_rows = 0
stat_keys = list(player_stats_template.keys())[1:]
# get stats table
table = soup.find_all('table', class_='wf-table')
for ratings_tag in table:
tbody = ratings_tag.find('tbody')
if tbody:
rows = tbody.find_all('tr')
for row in rows:
# extract all td that do not have a style attribute (no agent img & use % )
cols = row.find_all('td')
row_values = [col.text.strip() for col in cols if not col.has_attr('style')]
# If the number of columns matches our expected stats, process the row
if row_values and len(row_values) == len(stat_keys):
for i, key in enumerate(stat_keys):
# Accumulate values based on the key's expected data type
if isinstance(player_stats_template[key], int):
accumulator[key] += int(row_values[i].replace('%', ''))
else:
accumulator[key] += float(row_values[i])
num_rows += 1
# calculate averages
if num_rows > 0:
for key in accumulator:
if isinstance(player_stats_template[key], int):
# for intege use floor division
player_stats_template[key] = accumulator[key] // num_rows
else:
# for floating point round to two decimal places
player_stats_template[key] = round(accumulator[key] / num_rows, 2)
return player_stats_template
# florescent
player_num = '17976'
player_data = get_player_data(player_num)
if player_data:
print(player_data)
# Uncomment the code below to iterate through every player up to TOTAL_MAX_PLAYERS
# for i in range(1, TOTAL_MAX_PLAYERS + 1):
# player_num = str(i) # Convert player number to string for URL construction
# player_data = get_player_data(player_num)
# if player_data:
# print(player_data)
# break # Stop after finding and printing the first valid player data