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.2.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.2-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: howlongtobeat_scraper-1.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 3bc7765a5e93c89d8f58ce25d70f5b21fb1d36ae12d6ec51276932d6e85f25c7
MD5 995912af1f6722f30979ce4f52f89e2f
BLAKE2b-256 e3ecc506f728d200fa156c543b799fc3bdea297c7008a62156d810c904436db2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for howlongtobeat_scraper-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 32732b23e4abe3b9a5c3e5ec927e7bf8a5cd7a61edc67e3e79512218f1ac5738
MD5 b15932b226c8b318901a80eff2d7fae8
BLAKE2b-256 2274c26a7d07c1f0e6dfb479181d8ee97435e504ae2ce28e0dfca06bfd280473

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