A simple Python script that scrapes the FIDE website to retrieve current chess ratings for players by their FIDE ID.
Note: This project is my first experiment using spec-kit for structured, machine-readable specs. I've implemented it within the Cursor editor.
I had to step in during the research phase to provide HTML examples that support the planning phase for proper implementation of the scraping code.
- Python 3.11 or higher
- pip (Python package manager)
-
Install dependencies:
pip install -r requirements.txt
Or install manually:
pip install requests beautifulsoup4
The script supports two modes: Single FIDE ID mode (for one player) and Batch Processing mode (for multiple players from a file).
Run the script with a FIDE ID as an argument:
python fide_scraper.py 538026660Example Output:
Standard: 2830
Rapid: 2780
Blitz: 2760
Player with missing rating:
Standard: 2500
Rapid: 2450
Blitz: Unrated
Error - Invalid FIDE ID:
Error: Invalid FIDE ID format. Must be numeric (4-10 digits).
Error - Player not found:
Error: Player not found (FIDE ID: 99999999)
Error - Network issue:
Error: Unable to connect to FIDE website. Please check your internet connection.
Process multiple FIDE IDs from a file and output results to both a CSV file and the console.
Create a text file containing FIDE IDs, one per line:
Example (fide_ids.txt):
1503014
538026660
538020459
538027038
538042827
Notes:
- One FIDE ID per line
- Empty lines are allowed (will be skipped)
- Whitespace around IDs is automatically stripped
- File should be UTF-8 encoded
python fide_scraper.py --file fide_ids.txtOr using short form:
python fide_scraper.py -f fide_ids.txtConsole Output:
Processing FIDE IDs from file: fide_ids.txt
FIDE ID Player Name Standard Rapid Blitz
----------------------------------------------------------
1503014 Magnus Carlsen 2830 2780 2760
2016192 Hikaru Nakamura 2758 2800 2790
Output written to: fide_ratings_2025-01-27.csv
Processed 2 IDs successfully, 0 errors
CSV Output File:
- Filename:
fide_ratings_YYYY-MM-DD.csv(includes current date in ISO 8601 format) - Location: Current working directory
- Format: Standard CSV with proper escaping for special characters
- Columns: FIDE ID, Player Name, Standard, Rapid, Blitz
Example CSV Content:
FIDE ID,Player Name,Standard,Rapid,Blitz
1503014,Magnus Carlsen,2830,2780,2760
2016192,Hikaru Nakamura,2758,2800,2790
Error Handling in Batch Mode: The script continues processing even when individual FIDE IDs fail:
Processing FIDE IDs from file: fide_ids.txt
FIDE ID Player Name Standard Rapid Blitz
----------------------------------------------------------
1503014 Magnus Carlsen 2830 2780 2760
Error: Invalid FIDE ID format: abc123 (skipped)
2016192 Hikaru Nakamura 2758 2800 2790
Error: Player not found (FIDE ID: 99999999) (skipped)
Output written to: fide_ratings_2025-01-27.csv
Processed 2 IDs successfully, 2 errors
Batch Processing Features:
- Processes all valid FIDE IDs in the file
- Skips invalid IDs and continues processing
- Handles network errors gracefully (continues with remaining IDs)
- Generates CSV file with date-stamped filename
- Displays results in both CSV and console
- Provides summary of successful and failed processing
FIDE IDs can be found on:
- FIDE ratings website: https://ratings.fide.com
- Player profile pages
- Tournament results
FIDE IDs are typically 6-8 digit numbers (4-10 digits valid).
When using batch processing mode, the script generates a CSV file with the following characteristics:
- Filename:
fide_ratings_YYYY-MM-DD.csv(date in ISO 8601 format) - Encoding: UTF-8
- Delimiter: Comma
- Header Row: Yes (FIDE ID, Player Name, Standard, Rapid, Blitz)
- Special Characters: Automatically escaped (commas in names are quoted)
- Missing Ratings: Empty cell for missing/unrated ratings
The CSV file can be opened in:
- Microsoft Excel
- Google Sheets
- Any spreadsheet application
- Text editors
Note: If opening in Excel, you may need to specify UTF-8 encoding during import.
Run the test suite:
pytest tests/Run specific test file:
pytest tests/test_fide_scraper.py- Ensure dependencies are installed:
pip install -r requirements.txt
- Check your internet connection
- FIDE website may be temporarily unavailable
- Try again after a few moments
- In batch mode, individual timeouts won't stop processing of remaining IDs
- Verify the FIDE ID is correct
- Check that the player exists on the FIDE website
- Ensure the FIDE ID is numeric only
- In batch mode, these errors are logged but don't stop processing
- FIDE website structure may have changed
- Check if the website is accessible in a browser
- Report the issue if the website structure has changed
"File not found" error:
- Verify the file path is correct
- Use absolute path if relative path doesn't work:
python fide_scraper.py --file /full/path/to/file.txt - Check file permissions (must be readable)
"Permission denied" error:
- Check write permissions in current directory (needed for CSV output)
- Try running from a different directory with write access
Empty CSV file:
- Check that at least one FIDE ID in the file is valid
- Verify network connectivity
- Check console output for error messages
Special characters in player names:
- CSV file uses UTF-8 encoding
- Special characters should be preserved correctly
- If viewing in Excel, may need to specify UTF-8 import