GrandaddyOG GrandaddyOG - 2 years ago 256
JSON Question

Scraping- Error: No JSON object could be decoded

So i'm trying to scrape the table on this page for educational purposes:

My print response gives

<Response [200]>

This would mean it's good ,right? But when I put response.json() in a variable and try to print it out I get 'ValueError: No JSON Object could be decoded'

Here is my code :

import requests

headers = {
'accept-encoding': 'gzip, deflate, sdch, br',
'x-requested-with': 'XMLHttpRequest',
'accept-language': 'nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4',
'user-agent': 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
'accept': 'application/json, text/javascript, */*; q=0.01',
'referer': '',
'model-last-mode': 'GgVBlUgZgMvkAZA4DkgCYAYJauGyQ5BQAQW5ZLGd5qk=',
'authority': '',
'cookie': 'visid_incap_774904=E5yi1BIhTqKa7QY7CTHvbCgWQlcAAAAAQUIPAAAAAAAbmGcCJZ/yA5tiB2vsu1g6; crtg_rta=cc970250d%3Bcc300600d%3Bhw970250d%3B; incap_ses_128_774904=GEttC+rfv2wXecdRg7/GAUAaeVcAAAAA5ZSbfyTF02TorJxEKZxkUg==; _gat=1; _ga=GA1.2.1512369618.1463948865',

params = {
'category': 'shots',
'subcategory': 'zones',
'statsAccumulationType': '0',
'field': '',
'tournamentOptions': '',
'timeOfTheGameStart': '0',
'timeOfTheGameEnd': '5',
'teamIds': '',
'stageId': '12496',
'sortBy': 'Rating',
'sortAscending': '',
'page': '1',
'numberOfTeamsToPick': '',
'isCurrent': 'true',
'formation': ''

response = requests.get('', headers=headers, params=params)

data = response.json()
print data

Answer Source

You're printing an object, you need to call text attribute . Response object don't have a json attribute .

result = requests.get(url)
print result.text

If you want to get a json result, you will need to parse the result which is a string and convert it to a dict, and then use json.dumps to turn it into json

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download