A Python script for collecting and analyzing hockey game statistics from the Swedish Ice Hockey Federation's statistics website (stats.swehockey.se).
- Scrapes game schedules, lineups, and statistics from swehockey.se
- Tracks player statistics including:
- Games played
- Goals and assists
- Penalty minutes (PIM)
- Detailed event history
- Exports data to CSV files for further analysis
- Supports any league/tournament with a schedule ID
- Python 3.x
- pandas
- requests
- beautifulsoup4
-
Clone or download this repository
-
Install required packages:
pip install pandas requests beautifulsoup4Run the script with one or more schedule IDs as command-line arguments:
# Single schedule ID
python3 get_all_stats.py 19563
# Multiple schedule IDs
python3 get_all_stats.py 19563 19565 19701
# No arguments (uses default schedule ID: 19563)
python3 get_all_stats.pyThe script will:
- Process all provided schedule IDs sequentially
- Collect statistics from all games across all schedules
- Print combined statistics to the console
- Export combined data to CSV files
Schedule IDs can be found in the URL when viewing a schedule on stats.swehockey.se:
https://stats.swehockey.se/ScheduleAndResults/Schedule/19563
^^^^^
Schedule ID
Sample config.json:
{
"team_name_mapping": {
"AIS": "Almtuna IS",
"AIS1": "Almtuna IS",
"AIS2": "Almtuna IS",
"Almtuna IS Stockholm slutspelet U14P Kvartsfinal E3": "Almtuna IS",
"Almtuna IS Stockholm slutspelet U14P Semifinal E": "Almtuna IS",
"Almtuna IS Stockholm slutspelet U14P Final E": "Almtuna IS",
"Almtuna IS Stockholm slutspelet U13P Semifinal B": "Almtuna IS",
"Almtuna IS Stockholm slutspelet U15P Kvartsfinal B": "Almtuna IS"
},
"player_name_mapping": {
"John Dough": "John Doe"
}
}The script generates two CSV files:
Player summary statistics with columns:
TEAM- Team nameNUMBER- Player jersey numberNAME- Player nameGAMES PLAYED- Total games playedGOALS- Total goals scoredASSISTS- Total assistsPIM- Total penalty minutes
Detailed event log with columns:
DATE- Game dateGROUP- Tournament/league groupTYPE- Event type (GOAL, ASSIST, PIM)PLAYER NAME- Player namePLAYER TEAM- Player's teamHOME TEAM- Home team nameAWAY TEAM- Away team nameGAME ID- Unique game identifierGAME LINK- Direct link to game events page (https://stats.swehockey.se/Game/Events/[game_id])
Both CSV files use semicolon (;) as the delimiter for compatibility with Swedish locale spreadsheet applications.
- Find your tournament(s) on stats.swehockey.se
- Copy the schedule ID(s) from the URL
- Run the script with the schedule ID(s):
python3 get_all_stats.py 19563 19565 - Analyze the generated CSV files in Excel, Google Sheets, or your preferred tool
Some example tournament schedule IDs:
# U15 tournaments
python3 get_all_stats.py 19563 # U15P DM Röd Grupp 2
python3 get_all_stats.py 19565 # U15P DM Blå Grupp 2
# Multiple tournaments at once
python3 get_all_stats.py 19563 19565 # Both U15 groups
# SHL (Swedish Hockey League)
python3 get_all_stats.py 18263 # SHL 2024-2025Debug output can be controlled via the DEBUG variable at the top of the script:
DEBUG = 1 # Enable debug output
DEBUG = 0 # Disable debug output- The script processes all completed games (games with results)
- Games without results are automatically skipped
- Team names and player names are normalized to remove extra whitespace
- The script handles Swedish characters (Å, Ä, Ö) correctly
- Check your internet connection
- Verify the schedule ID is correct
- The swehockey.se website may be temporarily unavailable
- The game may not have been played yet
- The game result may not be published yet
- Verify the schedule ID has completed games with results
- Check that the tournament exists and is public
This project is for educational and personal use. Please respect the terms of service of stats.swehockey.se when scraping data.
Feel free to submit issues or pull requests for improvements or bug fixes.