I need the values in a dict. But item uses some abstraction on top of it. How to get the fields in a dict from an item ?
I know scrapy allows dict to be returned in place of item now. But I already am using item in my code, so how to convert it.
It looks to me like :
class Product(scrapy.Item):
name = scrapy.Field()
i = Product(name='foo)
print dict(i)
gets you a dictionary {'name': 'foo'}
vars(p)
p.__dict__
gets you: {'_values': {'name': 'foo'}}
If you don't want to create a new dictionary, just grab the _values key from the above:
vars(p)['_values']
p.__dict__['_values']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With