我需要字典中的值。但是item在它之上使用了一些抽象。如何从项目中获取字典中的字段?
我现在知道scrapy allows dict to be returned in place of item。但是我已经在代码中使用了item,因此如何进行转换。
最佳答案
在我看来:
class Product(scrapy.Item):
name = scrapy.Field()
i = Product(name='foo)
print dict(i)
为您提供字典{'name':'foo'}
vars(p)
p.__dict__
让您:
{'_values':{'name':'foo'}}
如果您不想创建新字典,只需从上面获取_values键:
vars(p)['_values']
p.__dict__['_values']
关于python - 如何从拼凑的物品中获取命令?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31855632/