'How do I parse the data on the website when scraping the web when the attribute I want is in the sub data?

I'm doing scrapping on a website and want to retrieve data on the 'stats' attribute then 'interest_count' data. But I don't know how to retrieve these attributes if they are in other data. I have tried with this code

stats =p['stats.interest_count']

but failed.

the data that I'm scrapping.

enter image description here

source code

products = r['data']
for p in products:
name = p['name']
price = p['price']
stok = p['stock']
stats =p['stats.interest_count']
count+=1
print('No :',count, 'name :',name, 'price:',price, 'stok :', stok, 'stats :', stats)
write = csv.writer(open('{}.csv'.format(key), 'a',newline=''))
data = [nama, harga, stok]
write.writerow(data)


Solution 1:[1]

You must access the attributes one at a time.

Try this

import json stats = json.loads(p['stats])['interest_count']

Or this

stats =p['stats']['interest_count']

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hanalia