class Item(scrapy.Item):
address = scrapy.Field()
state = scrapy.Field()
year = scrapy.Field(serializer=dict)
class Year(scrapy.Item):
first = scrapy.Field(serializer=dict)
second = scrapy.Field(serializer=dict)
class first(scrapy.Item):
amounts = scrapy.Field()
class second(scrapy.Item):
basic = scrapy.Field()
information = scrapy.Field()
Таким образом, вы можете сделать это:
>>> b = second(basic="hello", information="hello world")
>>> a = first(amounts=3)
>>> year = Year(first=a, second=b)
>>> year
{'first': {'amounts': 3},
'second': {'basic': 'hello', 'information': 'hello world'}}
>>> item = Item(address='address value', state='state value', year=year)
>>> item
{'address': 'address value',
'state': 'state value',
'year': {'first': {'amounts': 3}, 'second': {'basic': 'hello', 'information': 'hello world'}}}