So I’m writing a script to compare some data. One part of the data is in a JSON while the other part of the data is scraped from the internet. Overall my script works, but I can’t figure out how to modify the “count” value for each car.
JSON format:
[
{
"count: ": 0,
"car": "car01",
"types": "2",
"price": "$100",
"released": "2024"
},
{
"count: ": 0,
"car": "car02",
"types": "1",
"price": "$101",
"released": "2024"
},
]
python that compares json and web scrape:
#goes through ‘data’ which is the json file
#attribute = the html attribute value that I’m parsing from the scrape
#if i[‘car’] and att match, then a match was found, and I want to increment count +1 for key ‘count’ for that specific car
for i in data:
for att in attribute:
if i['car'] in att:
print("found ",i['car'])
else:
print("not found ",i['car'])
my orginal thought was to just use:
i['count'] += 1
but I have no idea how to specify the right count in the JSON file. Any thoughts or ideas would be greatly apricated!
Currently, my only other thought is maybe putting a header on each set of keys specifying the car value. But if it can be done without modifying the json, that would be ideal.