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

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:

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

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():
    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}")

if __name__ == "__main__":
    main()

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.0.tar.gz (16.4 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.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: howlongtobeat_scraper-1.1.0.tar.gz
  • Upload date:
  • Size: 16.4 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.0.tar.gz
Algorithm Hash digest
SHA256 d8ff049bdd7894131de51b445ca68241110fcf52040c71d2f5ab8dfa7fd5ecc0
MD5 af7d4c81706dbe38f3fcdf1a978297f5
BLAKE2b-256 bc49774f71274f42c9419645335d1e952f9747e5feb1a708823444dd321ef4a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for howlongtobeat_scraper-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3abf142a281b2ac928b41462a2955b75df0f0b41ec016868ace5caa820b82ff2
MD5 4954d57dcff40ec5fc782c2caa44a780
BLAKE2b-256 1162b351937156d6b58d54cfa6d19036da4eb115482b22db3d90be4467791689

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