1

This is the URL I'm trying to use python to pull back the json data from:

https://www.fangraphs.com/leaders.aspx?pos=all&stats=bat&lg=all&qual=y&type=8&season=2018&month=0&season1=2018&ind=0

This is the code (keep in mind I'm very new to learning Python):

import requests

url = 'https://www.fangraphs.com/leaders.aspx?'

params = dict(
    pos='all',
    stats='bat',
    lg='all',
    qual='y',
    type='8',
    season='2018',
    month='0',
    season1='2018',
    ind='0'
)

resp = requests.get(url=url, params=params)
data = resp.json()
print(data)

Am I setting this up right?

1 Answer 1

2

It looks like your response content is not in JSON notation, if you use print(resp.headers) you should see something like:

{
  'Cache-Control': 'private', 
  'Content-Type': 'text/html; charset=utf-8', 
  'Server': 'Microsoft-IIS/10.0', 
  'X-AspNet-Version': '4.0.30319', 
  'X-Powered-By': 'ASP.NET', 
  'Date': 'Thu, 07 Feb 2019 17:29:33 GMT', 
  'Content-Length': '313209'
}

As you can see the Content-Type is NOT JSON, so the decoder can't parse it. You might need to use BeautifulSoup or some other scraping solution.

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.