36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Dohvaća sezone i utakmice za HNS igrača preko Playwrighta."""
|
|
import json, sys, time
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
if len(sys.argv) < 2:
|
|
print("Koristi: hns_player_stats.py <hns_igrac_id>")
|
|
sys.exit(1)
|
|
|
|
hns_id = sys.argv[1]
|
|
url = f"https://semafor.hns.family/igraci/{hns_id}/"
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True)
|
|
page = browser.new_page()
|
|
page.goto(url, wait_until='networkidle', timeout=30000)
|
|
# dohvaćanje __NEXT_DATA__
|
|
next_data = page.inner_text('#__NEXT_DATA__')
|
|
data = json.loads(next_data)
|
|
browser.close()
|
|
|
|
# izvlačenje sezona i utakmica
|
|
props = data['props']['pageProps']
|
|
player = props.get('player', {})
|
|
seasons = player.get('seasons', [])
|
|
matches = props.get('matches', [])
|
|
|
|
print(f"Igrač: {player.get('name', '')} {player.get('surname', '')}")
|
|
print(f"Sezona: {len(seasons)}")
|
|
for s in seasons:
|
|
print(f" {s.get('season','?')} {s.get('competition','')} {s.get('clubName','')} "
|
|
f"N:{s.get('apps',0)} G:{s.get('goals',0)} A:{s.get('assists',0)}")
|
|
|
|
print(f"\nUtakmica: {len(matches)}")
|
|
for m in matches[:5]: # prvih 5
|
|
print(f" {m.get('date','')} {m.get('homeTeam','')} vs {m.get('awayTeam','')} {m.get('result','')}") |