Skip to content
Advertisement

Sportsreference Python returning empty dictionary for date that has games scheduled

I am having issues with the python API sportsreference, I am trying to pull information for every nba matchup on a given date. I have been able to do this for ncaab, ncaaf, and nfl but am finding that the nba returns an empty dictionary.

Current code is as follows:

from sportsreference.nba import boxscore
import sportsreference

from datetime import datetime

now = datetime.now()
box_scores_nba = sportsreference.nba.boxscore.Boxscores(now)

print(box_scores_nba.games)

Output is:

{’12-26-2020′: []}

Does anyone have any idea why I am not pulling any info when there are games scheduled this day? I have been trying to read the documentation for sportsreference and am getting nowhere.

Thanks –

Advertisement

Answer

Edited based on Comments

The BoxScore() method only gives a value for the previous day and does not give any detail for today/upcoming days, this is because the website itself does not provide these details! check here.

On the other hand you can get the schedule of a particular team using this code:

    from sportsreference.nba.schedule import Schedule
    
    houston_schedule = Schedule('HOU')
    for game in houston_schedule:
    
        print(game.date)  # Prints the date the game was played
        print(game.result)  # Prints whether the team won or lost

Even then there are incorrect output I receive in the dataset! Like the result of the upcoming games are shown as ‘win’.

enter image description here

In my opinion, it is better to avoid this API and go for better websites and use webscraping (unless you don’t want real-time data) as I find these results very raw, confusing and misleading here and there!

Advertisement