skip to Main Content

I am trying to get a dictionary that is inside of a script tag on a website. The dictionary is under the var product. I’ve successfully seperated the dictionary so that it’s on its own, however I’m getting the string indices error when I try to use the json. My code is shown below:

r = requests.get(URL).text
soup = BeautifulSoup(r, 'html.parser')
s = str(soup.find('script', type='text/javascript'))
data = json.loads(s.split('var product = ')[1].split('</script>')[0].split('new Shopify.OptionSelectors(')[0].split(',"images')[0] + '}')
print(data)

this returns:

{'id': 1940337819721, 'title': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON', 'handle': 'react-runner-mid-wr-ispa-black-white-anthracite-totalcrimson', 'description': '<span style="color: #ff0000;"><span style="color: #ff0000;">ufeff</span></span><meta charset="utf-8"><style type="text/css"><!--ntd {border:1px solid #ccc;}br {mso-data-placement:same-cell;}n--></style><span style="color: #ff0000;"><span data-sheets-value='{"1":2,"2":"This Launch Product is Final Sale. No refunds, exchanges or cancellations"}' data-sheets-userformat='{"2":6723,"3":{"1":0},"4":[null,2,16777215],"9":0,"12":0,"14":[null,2,16711680],"15":"Arial"}'>This Launch Product is Final Sale. No refunds, exchanges or cancellations</span></span>', 'published_at': '2018-12-12T05:00:00-08:00', 'created_at': '2018-11-28T13:35:00-08:00', 'vendor': 'NIKE', 'type': 'MENS FOOTWEAR', 'tags': ['18DEC', 'AT3143-001', 'block_ic', 'footwear', 'high', 'men', 'mens-footwear', 'new', 'nike', 'size_10', 'size_10-5', 'size_11', 'size_11-5', 'size_12', 'size_13', 'size_4', 'size_4-5', 'size_5', 'size_5-5', 'size_6', 'size_6-5', 'size_7', 'size_7-5', 'size_8', 'size_8-5', 'size_9', 'size_9-5', 'touch'], 'price': 17000, 'price_min': 17000, 'price_max': 17000, 'available': True, 'price_varies': False, 'compare_at_price': 17000, 'compare_at_price_min': 17000, 'compare_at_price_max': 17000, 'compare_at_price_varies': False, 'variants': [{'id': 17953124646985, 'title': '- / 4', 'option1': '-', 'option2': '4', 'option3': None, 'sku': 'AT3143-001---4', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 4', 'public_title': '- / 4', 'options': ['-', '4'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 33, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953124679753, 'title': '- / 4.5', 'option1': '-', 'option2': '4.5', 'option3': None, 'sku': 'AT3143-001---4.5', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 4.5', 'public_title': '- / 4.5', 'options': ['-', '4.5'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 33, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953124712521, 'title': '- / 5', 'option1': '-', 'option2': '5', 'option3': None, 'sku': 'AT3143-001---5', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 5', 'public_title': '- / 5', 'options': ['-', '5'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 33, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953124745289, 'title': '- / 5.5','option1': '-', 'option2': '5.5', 'option3': None, 'sku': 'AT3143-001---5.5', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True,'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 5.5', 'public_title': '- / 5.5', 'options': ['-', '5.5'], 'price': 17000, 'weight': 0,'compare_at_price': 17000, 'inventory_quantity': 33, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953124778057, 'title': '- / 6', 'option1': '-', 'option2': '6', 'option3': None, 'sku': 'AT3143-001---6', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available':True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 6', 'public_title': '- / 6', 'options': ['-', '6'], 'price': 17000, 'weight': 0,'compare_at_price': 17000, 'inventory_quantity': 33, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953124810825, 'title': '- / 6.5', 'option1': '-', 'option2': '6.5', 'option3': None, 'sku': 'AT3143-001---6.5', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 6.5', 'public_title': '- / 6.5', 'options': ['-', '6.5'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 33, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953124843593, 'title': '- / 7', 'option1': '-', 'option2': '7', 'option3': None, 'sku': 'AT3143-001---7', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 7', 'public_title': '- / 7', 'options': ['-', '7'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 33, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953124876361, 'title': '- / 7.5', 'option1': '-', 'option2': '7.5', 'option3': None, 'sku': 'AT3143-001---7.5', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 7.5', 'public_title': '- / 7.5', 'options': ['-', '7.5'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 32, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id':17953124909129, 'title': '- / 8', 'option1': '-', 'option2': '8', 'option3': None, 'sku': 'AT3143-001---8', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 8', 'public_title': '- / 8', 'options': ['-', '8'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 25, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id':17953124941897, 'title': '- / 8.5', 'option1': '-', 'option2': '8.5', 'option3': None, 'sku': 'AT3143-001---8.5', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 8.5', 'public_title': '- / 8.5', 'options': ['-', '8.5'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 17, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953124974665, 'title': '- / 9', 'option1': '-', 'option2': '9', 'option3': None, 'sku': 'AT3143-001---9', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 9', 'public_title': '- / 9', 'options': ['-', '9'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 35, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953125007433, 'title': '- / 9.5', 'option1': '-', 'option2': '9.5', 'option3': None, 'sku': 'AT3143-001---9.5', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 9.5', 'public_title': '- / 9.5', 'options': ['-', '9.5'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 36, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953125040201, 'title': '- / 10', 'option1': '-', 'option2': '10', 'option3': None, 'sku': 'AT3143-001---10', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 10', 'public_title': '- / 10', 'options': ['-', '10'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 82, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953125072969, 'title': '- / 10.5', 'option1': '-', 'option2': '10.5', 'option3': None, 'sku': 'AT3143-001---10.5', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 10.5', 'public_title': '- / 10.5', 'options': ['-', '10.5'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 35, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953125105737, 'title': '- / 11', 'option1': '-', 'option2': '11', 'option3': None, 'sku': 'AT3143-001---11', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 11', 'public_title': '- / 11', 'options': ['-', '11'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 35, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953125138505, 'title': '- / 11.5', 'option1': '-', 'option2': '11.5', 'option3': None, 'sku': 'AT3143-001---11.5', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON- - / 11.5', 'public_title': '- / 11.5', 'options': ['-', '11.5'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 25, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953125171273, 'title': '- / 12', 'option1': '-', 'option2': '12', 'option3': None, 'sku': 'AT3143-001---12', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 12', 'public_title': '- / 12', 'options': ['-', '12'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 10, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}, {'id': 17953125204041, 'title': '- / 13', 'option1': '-', 'option2': '13', 'option3': None, 'sku': 'AT3143-001---13', 'requires_shipping': True, 'taxable': True, 'featured_image': None, 'available': True, 'name': 'REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 13', 'public_title': '- / 13', 'options': ['-', '13'], 'price': 17000, 'weight': 0, 'compare_at_price': 17000, 'inventory_quantity': 25, 'inventory_management': 'shopify', 'inventory_policy': 'deny', 'barcode': None}]}

I’ve tried putting this in a json validator and it’s not valid, so I took off json.loads on the data variable:

data = s.split('var product = ')[1].split('</script>')[0].split('new Shopify.OptionSelectors(')[0].split(',"images')[0] + '}'

which returns a valid format of the json:

{"id":1940337819721,"title":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON","handle":"react-runner-mid-wr-ispa-black-white-anthracite-totalcrimson","description":"u003cspan style="color: #ff0000;"u003eu003cspan style="color: #ff0000;"u003eu003c/spanu003eu003c/spanu003eu003cmeta charset="utf-8"u003eu003cstyle type="text/css"u003eu003c!--ntd {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}n--u003eu003c/styleu003eu003cspan style="color: #ff0000;"u003eu003cspan data-sheets-value='{"1":2,"2":"This Launch Product is Final Sale. No refunds, exchanges or cancellations"}' data-sheets-userformat='{"2":6723,"3":{"1":0},"4":[null,2,16777215],"9":0,"12":0,"14":[null,2,16711680],"15":"Arial"}'u003eThis Launch Product is Final Sale. No refunds, exchanges or cancellationsu003c/spanu003eu003c/spanu003e","published_at":"2018-12-12T05:00:00-08:00","created_at":"2018-11-28T13:35:00-08:00","vendor":"NIKE","type":"MENS FOOTWEAR","tags":["18DEC","AT3143-001","block_ic","footwear","high","men","mens-footwear","new","nike","size_10","size_10-5","size_11","size_11-5","size_12","size_13","size_4","size_4-5","size_5","size_5-5","size_6","size_6-5","size_7","size_7-5","size_8","size_8-5","size_9","size_9-5","touch"],"price":17000,"price_min":17000,"price_max":17000,"available":true,"price_varies":false,"compare_at_price":17000,"compare_at_price_min":17000,"compare_at_price_max":17000,"compare_at_price_varies":false,"variants":[{"id":17953124646985,"title":"- / 4","option1":"-","option2":"4","option3":null,"sku":"AT3143-001---4","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 4","public_title":"- / 4","options":["-","4"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":33,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953124679753,"title":"- / 4.5","option1":"-","option2":"4.5","option3":null,"sku":"AT3143-001---4.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 4.5","public_title":"- / 4.5","options":["-","4.5"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":33,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953124712521,"title":"- / 5","option1":"-","option2":"5","option3":null,"sku":"AT3143-001---5","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 5","public_title":"- / 5","options":["-","5"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":33,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953124745289,"title":"- / 5.5","option1":"-","option2":"5.5","option3":null,"sku":"AT3143-001---5.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA -BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 5.5","public_title":"- / 5.5","options":["-","5.5"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":33,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953124778057,"title":"- / 6","option1":"-","option2":"6","option3":null,"sku":"AT3143-001---6","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 6","public_title":"- / 6","options":["-","6"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":33,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953124810825,"title":"- / 6.5","option1":"-","option2":"6.5","option3":null,"sku":"AT3143-001---6.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 6.5","public_title":"- / 6.5","options":["-","6.5"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":33,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953124843593,"title":"- / 7","option1":"-","option2":"7","option3":null,"sku":"AT3143-001---7","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 7","public_title":"- / 7","options":["-","7"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":33,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953124876361,"title":"- / 7.5","option1":"-","option2":"7.5","option3":null,"sku":"AT3143-001---7.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 7.5","public_title":"- / 7.5","options":["-","7.5"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":32,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953124909129,"title":"- / 8","option1":"-","option2":"8","option3":null,"sku":"AT3143-001---8","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 8","public_title":"- / 8","options":["-","8"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":25,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953124941897,"title":"- / 8.5","option1":"-","option2":"8.5","option3":null,"sku":"AT3143-001---8.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 8.5","public_title":"- / 8.5","options":["-","8.5"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":17,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953124974665,"title":"- / 9","option1":"-","option2":"9","option3":null,"sku":"AT3143-001---9","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 9","public_title":"- / 9","options":["-","9"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":35,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953125007433,"title":"- / 9.5","option1":"-","option2":"9.5","option3":null,"sku":"AT3143-001---9.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 9.5","public_title":"- / 9.5","options":["-","9.5"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":36,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953125040201,"title":"- / 10","option1":"-","option2":"10","option3":null,"sku":"AT3143-001---10","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 10","public_title":"- / 10","options":["-","10"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":82,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953125072969,"title":"- / 10.5","option1":"-","option2":"10.5","option3":null,"sku":"AT3143-001---10.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 10.5","public_title":"- / 10.5","options":["-","10.5"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":35,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953125105737,"title":"- / 11","option1":"-","option2":"11","option3":null,"sku":"AT3143-001---11","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 11","public_title":"- / 11","options":["-","11"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":35,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953125138505,"title":"- / 11.5","option1":"-","option2":"11.5","option3":null,"sku":"AT3143-001---11.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 11.5","public_title":"- / 11.5","options":["-","11.5"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":25,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953125171273,"title":"- / 12","option1":"-","option2":"12","option3":null,"sku":"AT3143-001---12","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 12","public_title":"- / 12","options":["-","12"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":10,"inventory_management":"shopify","inventory_policy":"deny","barcode":null},{"id":17953125204041,"title":"- / 13","option1":"-","option2":"13","option3":null,"sku":"AT3143-001---13","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"REACT RUNNER MID WR ISPA - BLACK/WHITE/ANTHRACITE/TOTALCRIMSON - - / 13","public_title":"- / 13","options":["-","13"],"price":17000,"weight":0,"compare_at_price":17000,"inventory_quantity":25,"inventory_management":"shopify","inventory_policy":"deny","barcode":null}]}

however I’m still getting the same error when I try to call for example

data['variants']

any idea what the issue is?

2

Answers


  1. Chosen as BEST ANSWER

    you can copy the first return in your question, and just let data = your_copy, then data['variants'], it works – Xiao Tan


  2. The problem with your data dictionary is that it includes values which aren’t valid Python. For example, you have "available":true,. Python sees this and looks for a variable named true, not the Boolean, True (capital ‘T’). The same sort of thing goes for false and null.

    One hack you could use is just make variables with those names. Then data['variants'] should work.

    true = True
    false = False
    null = None
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search