HowLongToBeat Scraper
A Python package to get game completion times from HowLongToBeat.
This package provides both a command-line tool and a Python API to look up a game and retrieve its estimated times for main story, extras, and 100% completion.
Features
- Command-Line Interface (CLI): Get game times directly from your terminal.
- Python API: Easily integrate HowLongToBeat functionality into your own Python scripts.
- Co-Op Game Support: Automatically detects and extracts both Solo and Co-Op playtimes for cooperative games.
- Traditional Game Support: Handles standard games with Main Story, Main + Extras, and Completionist times.
- Asynchronous: Built on
asyncioandplaywrightfor efficient performance. - Structured Data: Returns data in a
dataclassfor easy access. - Robust Parsing: Updated selectors ensure compatibility with HowLongToBeat's current website structure.
Installation
From PyPI (Official Release)
Install the package from the official Python Package Index:
pip install howlongtobeat-scraper
After installation, you need to install Playwright browsers:
playwright install
Note: The package is now officially available on PyPI at: https://pypi.org/project/howlongtobeat-scraper/
From Source (for Development)
If you want to contribute or install the latest development version, you can clone the repository and install it in editable mode:
git clone https://github.com/Sermodi/HowLongToBeat_scraper.git
cd HowLongToBeat_scraper
pip install -e .
Usage
Command-Line Interface (CLI)
Once installed, you can run the package as a module:
python -m howlongtobeat_scraper "The Witcher 3: Wild Hunt"
Note: Use the module format above as it works consistently across all platforms.
Example Output (Traditional Game):
Searching for "The Witcher 3: Wild Hunt"...
Title: The Witcher 3: Wild Hunt
- Main Story: 51.5 hours
- Main + Extras: 103 hours
- Completionist: 172 hours
Example Output (Co-Op Game):
Searching for "It Takes Two"...
Title: It Takes Two
- Solo: 14 hours
- Co-Op: 14 hours
Python API
The package provides two main functions for retrieving game data:
Recommended: get_game_stats_smart (with automatic fallback)
This is the recommended function that automatically handles browser visibility for you:
from __future__ import annotations
from howlongtobeat_scraper.api import get_game_stats_smart, GameData
def main():
# Example with traditional game
game_name = "Celeste"
print(f"--- Fetching data for: {game_name} ---")
try:
# Smart function with automatic fallback
# Tries headless first, falls back to visible mode if needed
game_data: GameData | None = get_game_stats_smart(game_name)
if game_data:
print("API call successful. Data received:")
print(f" Title: {game_data.title}")
print(f" Main Story: {game_data.main_story} hours")
print(f" Main + Extras: {game_data.main_extra} hours")
print(f" Completionist: {game_data.completionist} hours")
else:
print("No data found for the game.")
except Exception as e:
print(f"An error occurred: {e}")
# Example with Co-Op game
coop_game = "It Takes Two"
print(f"\n--- Fetching data for: {coop_game} ---")
try:
coop_data: GameData | None = get_game_stats_smart(coop_game)
if coop_data:
print("API call successful. Data received:")
print(f" Title: {coop_data.title}")
print(f" Solo: {coop_data.solo} hours")
print(f" Co-Op: {coop_data.coop} hours")
else:
print("No data found for the game.")
except Exception as e:
print(f"An error occurred: {e}")
Manual control: get_game_stats
For manual control over browser visibility, you can use the original function:
from howlongtobeat_scraper.api import get_game_stats
# Always headless (invisible browser)
game_data = get_game_stats("Game Name")
# Always visible browser (for debugging or when headless fails)
game_data = get_game_stats("Game Name", headless=False)
Browser Visibility and Fallback Strategy
Automatic Fallback (Recommended)
The get_game_stats_smart function implements an intelligent fallback strategy:
- First attempt: Tries headless mode (invisible browser) for better performance
- Automatic fallback: If headless fails due to bot detection, automatically retries with visible browser
- User-friendly: Minimizes browser visibility while ensuring reliability
# Recommended: automatic fallback strategy
data = get_game_stats_smart("Game Name")
Manual Control
For specific use cases, you can manually control browser visibility with get_game_stats:
get_game_stats("Game Name"): Always uses headless mode (invisible)get_game_stats("Game Name", headless=False): Always shows browser window
# Always headless (faster but may fail on some sites)
data = get_game_stats("Game Name")
# Always visible (more reliable but shows browser window)
data = get_game_stats("Game Name", headless=False)
Recommendation: Use get_game_stats_smart() for the best balance of performance and reliability.
Spanish Documentation
A Spanish version of this README is available at README.es.md.
Metadata
Release files for howlongtobeat-scraper 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| howlongtobeat_scraper-1.1.3.tar.gz | 18.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| howlongtobeat_scraper-1.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.8 kB
Release files / howlongtobeat_scraper-1.1.3.tar.gz
| Download URL | howlongtobeat_scraper-1.1.3.tar.gz |
|---|---|
| Size | 18.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c6bb83800b802dc037022d21a99e645386e4b9e24155f0bbc9b61f0598183f3c
|
|
BLAKE2b-256 checksum How to use checksums |
62bc630d38cae63ab373245087120bb3725f29e150970e32da7a319f92fe90d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / howlongtobeat_scraper-1.1.3-py3-none-any.whl
| Download URL | howlongtobeat_scraper-1.1.3-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d659f3fe99eb24f16750b16bc9868b2194e27eaded994c55ba03a57d315908f
|
|
BLAKE2b-256 checksum How to use checksums |
03f66d18a48e74ca2341b777f96d3f6cdc19950446dd29ccddbe803ac8e7f7a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for howlongtobeat-scraper 1.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.