在哪里可以找到2020年的NFL XML时间表数据



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

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()

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

https://static.nfl.com/ajax/scorestrip?season=2020&季节类型=REG&周=2

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

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

使用'https://static.nfl.com/ajax/scorestrip?或者只是用static替换www部分,你就可以开始了。

最新更新