@@ -182,21 +182,32 @@ output processors to use: in the :ref:`Item Field <topics-items-fields>`
182
182
metadata. Here is an example::
183
183
184
184
import scrapy
185
- from scrapy.contrib.loader.processor import MapCompose, Join, TakeFirst
186
- from w3lib.html import remove_entities
187
- from myproject.utils import filter_prices
185
+ from scrapy.contrib.loader.processor import Join, MapCompose, TakeFirst
186
+ from w3lib.html import remove_tags
187
+
188
+ def filter_price(value):
189
+ if value.isdigit():
190
+ return value
188
191
189
192
class Product(scrapy.Item):
190
193
name = scrapy.Field(
191
- input_processor=MapCompose(remove_entities ),
194
+ input_processor=MapCompose(remove_tags ),
192
195
output_processor=Join(),
193
196
)
194
197
price = scrapy.Field(
195
- default=0,
196
- input_processor=MapCompose(remove_entities, filter_prices),
198
+ input_processor=MapCompose(remove_tags, filter_price),
197
199
output_processor=TakeFirst(),
198
200
)
199
201
202
+ ::
203
+
204
+ >>> from scrapy.contrib.loader import ItemLoader
205
+ >>> il = ItemLoader(item=Product())
206
+ >>> il.add_value('name', [u'Welcome to my', u'<strong>website</strong>'])
207
+ >>> il.add_value('price', [u'€', u'<span>1000</span>'])
208
+ >>> il.load_item()
209
+ {'name': u'Welcome to my website', 'price': u'1000'}
210
+
200
211
The precedence order, for both input and output processors, is as follows:
201
212
202
213
1. Item Loader field-specific attributes: ``field_in `` and ``field_out `` (most
0 commit comments