I have a nested JSON (API) webstie which i want to parse and save items to file (using Scrapy framework).
I want to access each subelement of given elements, those are in following format
0 {…}
1 {…}
2 {…}
3 {…}
4 {…}
5 {…}
6 {…}
7 {…}
8 {…}
9 {…}
10 {…}
If I expand element 0 i get following values, where {...} exapnds further
id 6738
date "2018-06-14T09:38:51"
date_gmt "2018-06-14T09:38:51"
guid
rendered "https:example.com"
modified "2019-03-19T20:43:50"
modified_gmt "2019-03-19T20:43:50"
How does it look like in reality
How do I access, consecutively, each element, first 0, then 1, then 2 ... up to total of 350 and grab value of, for example
guid
rendered "https//:example.com"
and save it to item.
What I have:
results = json.loads(response.body_as_unicode())
item = DataItem()
for var in results:
item['guid'] = results["guid"]
yield item
This fails with
TypeError: list indices must be integers, not str
I know that i can access it with
item['guid'] = results[0]["guid"]
But this only gives me [0] index of the whole list and I want to iterate through all of indexes. How do I pass index number inside of the list?
0with something uhm, like a variable? or the length?resultsto get instant help.