Skip to main content

Un scraper para obtener los tiempos de juego desde HowLongToBeat.com.

Project description

HowLongToBeat Scraper

PyPI version Python versions License: MIT Downloads Code style: black

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 asyncio and playwright for efficient performance.
  • Structured Data: Returns data in a dataclass for 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:

  1. First attempt: Tries headless mode (invisible browser) for better performance
  2. Automatic fallback: If headless fails due to bot detection, automatically retries with visible browser
  3. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

howlongtobeat_scraper-1.1.1.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

howlongtobeat_scraper-1.1.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file howlongtobeat_scraper-1.1.1.tar.gz.

File metadata

  • Download URL: howlongtobeat_scraper-1.1.1.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for howlongtobeat_scraper-1.1.1.tar.gz
Algorithm Hash digest
SHA256 85206d340dcfb34347a5f9c66730642097b2e2b3c2ebda7cb25ccb9f04fd82cc
MD5 27b3dc7dd0d257ea72640d01251341bc
BLAKE2b-256 d6b06f069784137d3c300d08f4dabbb91ce0dc1d4cf321f216d00c2e100a2c0f

See more details on using hashes here.

File details

Details for the file howlongtobeat_scraper-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for howlongtobeat_scraper-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7bc49fa5dfede70dc381ee9225ca57fbe6c6bc175b494980847faf30fdd88d5a
MD5 624389f34f46abeb6026b868cf6fa6df
BLAKE2b-256 3fb6ca645289f01bc8226d09c40984297f96062e7c1eb0ad1cf145bd6ff5b17a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page