You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Python代码以仅抓取LiveScore网站的实时足球比赛数据?

Solution: Filter Live Matches & Fetch Current Match Minute

Let's fix your code to only capture in-progress matches and pull the live minute count instead of kickoff time. Here's how to adjust it step by step:

import requests
import pandas as pd

url = "https://prod-public-api.livescore.com/v1/api/react/date/soccer/20220309/0.00?MD=1"
jsonData = requests.get(url).json()
rows = []

for stage in jsonData['Stages']:
    events = stage['Events']
    for event in events:
        # Only keep matches that are currently live (status code 2 = in progress)
        if event.get('St') == 2:
            home_team = event['T1'][0]['Nm']
            away_team = event['T2'][0]['Nm']
            # Grab live minute (supports stoppage time like "90+3")
            current_minute = event.get('Min', 'N/A')
            
            row = {
                'Home Team': home_team,
                'Away Team': away_team,
                'Current Minute': current_minute
            }
            rows.append(row)

# Build the final DataFrame with live match data
live_matches_df = pd.DataFrame(rows)
print(live_matches_df)

Key Details:

  • Live Match Filter: The St field in each event object tells us the match state. A value of 2 means the game is actively in progress (other common codes: 0 = not started, 3 = finished).
  • Current Minute Handling: The Min field directly returns the live time, including stoppage time in formats like 45+2 or 90+5. We use event.get() to fall back to N/A just in case the field is missing (rare for live games).
  • Removed Kickoff Time: Since we're only targeting live matches, we don't need to parse the Esd kickoff timestamp anymore.

Quick Tip:

To dynamically fetch today's live matches instead of hardcoding the date (20220309), generate the current date in YYYYMMDD format with:

from datetime import datetime
today_date = datetime.today().strftime('%Y%m%d')
url = f"https://prod-public-api.livescore.com/v1/api/react/date/soccer/{today_date}/0.00?MD=1"

内容的提问来源于stack exchange,提问作者Carolino

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 15:07:47