Creating such a Python script involves several steps, including fetching web pages, parsing the HTML content, extracting the necessary data, and then storing and visualizing this data. Since the website's content and structure might be dynamic and subject to change, the script provided here is based on the structure as it exists at the time of writing and might need adjustments in the future.
Make sure you have the necessary libraries installed. You'll principally need requests and bs4 (Beautiful Soup) for web scraping, and you might use matplotlib or seaborn for visualization.
- Install necessary packages (if you haven't already):
pip install requests bs4 matplotlib seaborn
- Here's an example script to fetch the first 50 team names and links from the given page, then fetch their match histories, and store this information. Creating visual representations of when each team plays will follow.
import requests
from bs4 import BeautifulSoup
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
BASE_URL = "https://logs.stormforge.gg"
def fetch_teams():
ladder_url = f"{BASE_URL}/en/ladder/netherwing/2v2"
page = requests.get(ladder_url)
soup = BeautifulSoup(page.content, 'html.parser')
teams = soup.findAll('tr', {'class': 'c-playerLadder__entry'})[:50] # assuming each team is within such an element
team_data = []
for team in teams:
team_link_tag = team.find('a', href=True)
team_name = team_link_tag.text.strip()
team_link = BASE_URL + team_link_tag['href']
team_data.append((team_name, team_link))
return team_data
def fetch_match_history(team_link):
page = requests.get(team_link)
soup = BeautifulSoup(page.content, 'html.parser')
matches = soup.findAll('a', {'class': 'c-matchHistory__entry'}) # assuming the matches are contained within such elements
match_data = []
for match in matches:
match_link = BASE_URL + match['href']
match_data.append(match_link)
return match_data
def main():
teams = fetch_teams()
all_team_matches = {}
for name, link in teams:
matches = fetch_match_history(link)
print(f"Fetched {len(matches)} matches for team {name}")
all_team_matches[name] = matches
# Example of storing this info; more work needed to structure as per your need & visualization
with open('team_matches.txt', 'w') as f:
for team, matches in all_team_matches.items():
f.write(f"Team: {team}\n")
for match in matches:
f.write(f"{match}\n")
f.write("\n")
main()
This script is quite basic and doesn't account for the pagination of match histories or the specific structure of the match history URLs—it merely demonstrates how to begin scraping the ladder page and individual team pages. Real-world usage might require further refinement to accurately parse and store the data you're interested in.
Moreover, visualizing when teams play, given the match timestamp data, would involve parsing these timestamps (you'd need to extract these from the match history pages, which isn't covered above) and utilizing something like matplotlib or seaborn to create time-based plots. This also would mean managing and interpreting datetime values in Python, which could be approached with the datetime or pandas libraries once you have the required timestamp data.