Where to find NFL XML Schedule Data for 2020

Viewed 1753

I have been pulling schedules from the nfl xml data using the nflgame and nfldb modules, however I noticed that the URLs generated using the below function returns a 404 error. Has anyone else experienced this recently and know why this is the case?

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 Answers

nfl.com restructured their site and APIs. nflgame relied heavily on that, which now no longer works. You will need to find an alternative to get the nfl schedule, live scores, updates, play-by-play, etc.

You can get the schedule though from 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()
Related