Default values for Item Fields()

1,648 views
Skip to first unread message

crawler

unread,
Apr 28, 2012, 10:03:00 AM4/28/12
to scrapy...@googlegroups.com
What is the easiest way to set default values for Item Fields()?

Steven Almeroth

unread,
Apr 29, 2012, 12:12:56 PM4/29/12
to scrapy...@googlegroups.com
See this thread from december: https://groups.google.com/d/topic/scrapy-users/X963mAiKNco/discussion

"The reason why field defaults was removed from Scrapy is because there were many ways to implement default field values depending on the project with slightly different semantics..."

Pablo Hoffman

unread,
May 9, 2012, 3:42:22 AM5/9/12
to scrapy...@googlegroups.com, Steven Almeroth
A simple (and common) way to do it is to write an item pipeline to set the default values.

For example:
class DefaultValuesPipeline(object):

    def process_item(self, item, spider):
        item.setdefault('field1', 'value1')
        item.setdefault('field2', 'value2')
        # ...
        return item
--
You received this message because you are subscribed to the Google Groups "scrapy-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/scrapy-users/-/u-zLCpuO8KUJ.
To post to this group, send email to scrapy...@googlegroups.com.
To unsubscribe from this group, send email to scrapy-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scrapy-users?hl=en.
Reply all
Reply to author
Forward
0 new messages