Scrapy - Creating Nested Json Object
I'm learning how to work with Scrapy while refreshing my knowledge in Python?/Coding from school. Currently, I'm playing around with imdb top 250 list but struggling with a JSON ou
Solution 1:
Question: ... struggling with a JSON output file
Note: Can't use your
ActorsSpider
, get Error: Pseudo-elements are not supported.
# Define a `dict` **once**
top250ImdbItem = {'movies': []}
defparse_actor(self, response):
poster = response.css(...
title = response.css(...
photos = response.css(...
actors = response.css(...
# Assuming List of Actors are in sync with List of Photos
actors_list = []
for i, actor inenumerate(actors):
actors_list.append({"name": actor, "photo": photos[i]})
one_movie = {"poster": poster,
"title": title,
"actors": actors_list
}
# Append One Movie to Top250 'movies' List
top250ImdbItem['movies'].append(one_movie)
Post a Comment for "Scrapy - Creating Nested Json Object"