Scraper minimalista para datos de tiros de Sofascore
Project description
JekeScore
Scraper minimalista para obtener datos de tiros (shotmap) de Sofascore.
Requisitos
- Python 3.13+
- pyenv (recomendado)
Instalación
1. Configurar Python con pyenv
# Instalar Python 3.13.11
pyenv install 3.13.11
# Clonar el repositorio
git clone https://github.com/jekedelasdeportivas/jekescore.git
cd jekescore
# pyenv usará automáticamente la versión del archivo .python-version
python --version # Debería mostrar 3.13.11
2. Crear entorno virtual
# Crear venv
python -m venv venv
# Activar venv
# Linux/macOS:
source venv/bin/activate
# Windows:
venv\Scripts\activate
# Instalar dependencias
pip install -e ".[dev]"
Uso rápido
from jekescore import get_shotmap
# Obtener tiros de un partido
shots = get_shotmap(match_id=12557619)
# Iterar sobre los tiros
for shot in shots:
print(f"{shot.player.name}: ({shot.x}, {shot.y}) - {shot.shot_type}")
# Filtrar solo goles
for goal in shots.goals:
print(f"GOL de {goal.player.name} min {goal.time}'")
# Tiros por equipo
print(f"Tiros local: {len(shots.home_shots)}")
print(f"Tiros visitante: {len(shots.away_shots)}")
Configuración
Plataforma
Por defecto usa User-Agent de Windows. Puedes cambiarlo:
from jekescore import get_shotmap
# Para macOS
shots = get_shotmap(match_id=12557619, platform="macos")
# Para Linux
shots = get_shotmap(match_id=12557619, platform="linux")
Cookies (si hay problemas de acceso)
Si Sofascore bloquea las peticiones, puedes usar cookies de tu navegador:
from jekescore import JekeScoreClient
# Opción 1: Diccionario de cookies
client = JekeScoreClient(cookies={"session": "abc123"})
# Opción 2: Archivo JSON (exportado de Selenium o DevTools)
client = JekeScoreClient(cookies_file="cookies.json")
shots = client.get_shotmap(12557619)
Estructura de datos
Shot
Cada tiro contiene:
| Campo | Tipo | Descripción |
|---|---|---|
id |
int | ID único del tiro |
time |
int | Minuto del partido |
player |
Player | Jugador que disparó |
x, y |
float | Coordenadas del disparo |
shot_type |
str | goal, save, miss, block |
situation |
str | corner, assisted, set-piece, fast-break |
body_part |
str | head, right-foot, left-foot |
is_goal |
bool | True si fue gol |
Coordenadas
Las coordenadas están normalizadas:
x: 0-100 (ancho del campo, 0 = portería rival)y: 0-100 (alto del campo)
Obtener match_id
El match_id está en la URL del partido:
https://www.sofascore.com/football/match/team1-team2/ABC#id:12557619
^^^^^^^^
match_id
También puedes extraerlo programáticamente:
from jekescore import JekeScoreClient
url = "https://www.sofascore.com/football/match/barcelona-atalanta/OgbsKgb#id:12557619"
match_id = JekeScoreClient.get_match_id_from_url(url)
print(match_id) # 12557619
Desarrollo
# Activar entorno virtual
source venv/bin/activate
# Ejecutar linter
ruff check .
# Ejecutar formatter
ruff format .
# Ejecutar type checker
pyright .
# Ejecutar tests
pytest
# Ejecutar tests con coverage
pytest --cov
Licencia
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jekescore-0.1.0.tar.gz.
File metadata
- Download URL: jekescore-0.1.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b167e3c7ae0074ec10887088f08a2c89573b0ed6dca5d9ee44c3c818f32298d
|
|
| MD5 |
6f75f834a48867822a2147c5acc554ce
|
|
| BLAKE2b-256 |
fe90e8aff1f325f83db0395a57dedb91c75cdf4c0093d296cb6fffd1455645bb
|
File details
Details for the file jekescore-0.1.0-py3-none-any.whl.
File metadata
- Download URL: jekescore-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
244a540166c8af7238cda62af473843972d8bfe9d937b583932095dd954f32f6
|
|
| MD5 |
2ee5066fadc201dcc19b09b194180333
|
|
| BLAKE2b-256 |
618d9ebc74553996a019a6baf517db180b67ff26a71a0a1da2fbdbc55512ad54
|