0

I'm trying to parse the information found in this link here: http://stats.nba.com/stats/playergamelog?DateFrom=&DateTo=&LeagueID=00&PlayerID=203518&Season=2016-17&SeasonType=Pre+Season

What I want to pull is the information under rowSet (so 0, 1, 2, etc will be one entry) enter image description here

Code I'm using:

import requests
urlPlayerLog = "http://stats.nba.com/stats/playergamelog?DateFrom=&DateTo=&LeagueID=00&PlayerID=203518&Season=2016-17&SeasonType=Pre+Season"
responses = requests.get(urlPlayerLog)
dataGameLogs = responses.json()['resultSets'][0]['rowSet']

This was working for me for months and then one day I kept getting the following error: enter image description here

Which made me think the issue was with dataGameLogs = responses.json()['resultSets'][0]['rowSet'] , but unsure why that is returning an error...

1
  • I likely means that the server didn't give you any data. I ran your url several times. The first time I got data, but after that I got nothing. You could peek at responses.text to see if you got anything before proceeding. Commented Oct 12, 2016 at 21:08

1 Answer 1

1

The webpage might be expecting a web browser to request the data from the URL. Try adding a user-agent to your request.

import requests
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/31.0'}
urlPlayerLog = "http://stats.nba.com/stats/playergamelog?DateFrom=&DateTo=&LeagueID=00&PlayerID=203518&Season=2016-17&SeasonType=Pre+Season"
responses = requests.get(urlPlayerLog, headers=HEADERS)
dataGameLogs = responses.json()['resultSets'][0]['rowSet']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.