mirror of https://github.com/scrapy/scrapy.git
Added serialization functions to newitem
This commit is contained in:
parent
426282bbc9
commit
77b25d3036
|
|
@ -0,0 +1,18 @@
|
|||
import simplejson
|
||||
|
||||
from scrapy.utils.serialization import ScrapyJSONEncoder
|
||||
|
||||
|
||||
def item_to_dict(item):
|
||||
"""Returns a dict representation of an item"""
|
||||
res = {}
|
||||
for field in item.fields:
|
||||
res[field] = getattr(item, field)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def item_to_json(item):
|
||||
"""Returns a json representation of an item"""
|
||||
return simplejson.dumps(item_to_dict(item), cls=ScrapyJSONEncoder)
|
||||
|
||||
Loading…
Reference in New Issue