1

This is my code below:

from urllib.request import urlopen
import json
import requests

url = 'https://production-us-adidasgroup.demandware.net/s/adidas-US/dw/shop/v15_6/products/(CQ1862)?client_id=392f521c-cf82-4c24-8ee4-97b4bfe926c5&expand=availability,variations,prices&callback=jQuery311046436681352330944_1508679685699&_=1508679685720.json'

s = requests.session()

res = s.get(url)
json_dict = res.json()

qty = json_dict['inventory']['ats']

print(qty)

I am trying to parse the 'ats' from the url, but keep running into error:

simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I think it's because in the URL the first line doesn't have value. Is there any way to skip this? I know I'm not using some of the modules I have imported.

Vega
  • 27,856
  • 27
  • 95
  • 103

1 Answers1

1

The problem is that you are receiving a JSONP response which includes a function name. If you curl that URL you'll see the response starts with /**/jQuery311046436681352330944_1508679685699({. This is the same value you can see in the URL: callback=jQuery311046436681352330944_1508679685699

To get rid of this, drop the callback parameter from the URL. Use https://production-us-adidasgroup.demandware.net/s/adidas-US/dw/shop/v15_6/products/(CQ1862)?client_id=392f521c-cf82-4c24-8ee4-97b4bfe926c5&expand=availability,variations,prices&_=1508679685720.json instead.

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166