2020 年 NFL 赛程 XML 数据在哪里可以找到?

4

我一直在使用nflgame和nfldb模块从nfl xml数据中提取时间表,但是我发现下面的函数生成的URL返回404错误。是否还有其他人最近遇到了这个问题,知道原因是什么?

def schedule_url(year, stype, week):
    """
    Returns the NFL.com XML schedule URL. `year` should be an
    integer, `stype` should be one of the strings `PRE`, `REG` or
    `POST`, and `gsis_week` should be a value in the range
    `[0, 17]`.
    """
    xmlurl = 'http://www.nfl.com/ajax/scorestrip?'
    if stype == 'POST':
        week += 17
        if week == 21:  # NFL.com you so silly
            week += 1
    return '%sseason=%d&seasonType=%s&week=%d' % (xmlurl, year, stype, week)

schedule_url(2019, 'REG', 1)
3个回答

3
nfl.com 重构了其网站和 API。nflgame 在很大程度上依赖于它,但现在不再起作用。您需要找到替代方案来获取 NFL 赛程、实时比分、更新、逐个进行等信息。
您可以从 ESPN 端点 中获取赛程安排。
import requests
headers = {'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Mobile Safari/537.36'}
url = "http://site.api.espn.com/apis/site/v2/sports/football/nfl/scoreboard"
payload = {'week':'1'}

jsonData = requests.get(url, headers=headers, params=payload).json()

2

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接