【问题标题】:Where to find NFL XML Schedule Data for 2020哪里可以找到 2020 年 NFL XML 赛程数据
【发布时间】:2020-09-15 20:27:55
【问题描述】:

我一直在使用 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)

【问题讨论】:

    标签: python xml


    【解决方案1】:

    nfl.com 重组了他们的网站和 API。 nflgame 严重依赖它,现在它不再有效。您需要找到替代方案来获取 nfl 赛程、实时比分、更新、逐场比赛等。

    您可以从ESPN endpoints获取日程安排

    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】:

      另外,对于未来的游戏,新的网站格式是:

      https://static.nfl.com/ajax/scorestrip?season=2020&seasonType=REG&week=2

      【讨论】:

        【解决方案3】:

        这是我用来获取分数的方法,因为旧的不再起作用了。

        https://static.nfl.com/liveupdate/scorestrip/ss.xml

        使用“https://static.nfl.com/ajax/scorestrip?”或者只需将 www 部分替换为 static 即可。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-04-12
          • 1970-01-01
          • 2015-06-21
          • 2020-01-30
          • 1970-01-01
          • 1970-01-01
          • 2015-04-08
          • 2011-05-09
          相关资源
          最近更新 更多