Created
February 12, 2014 23:39
-
-
Save nyov/8966849 to your computer and use it in GitHub Desktop.
scrapy item with default values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DefaultsItem(Item): | |
""" Item with default values """ | |
def __getitem__(self, key): | |
try: | |
return self._values[key] | |
except KeyError: | |
field = self.fields[key] | |
if 'default' in field: | |
return field['default'] | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/nyov/scrapyext/blob/master/scrapyext/defaultsitem.py