D
D
Dennis2016-07-24 16:55:37
Python
Dennis, 2016-07-24 16:55:37

Scrapy - input_processor?

Hi all!
items.py:

import scrapy
from scrapy.loader.processors import MapCompose

def filter_spaces(value):
    return value.strip(" ").strip("\n")

class LotItem(scrapy.Item):
    num = scrapy.Field(input_processor=MapCompose(filter_spaces))

spider.py:
def parse_item(self, response):
    item = LotItem()                    
    item['num'] = response.xpath('//div/span/text()').extract()[0]
    yield item

response.xpath('//div/span/text()').extract() returns a string like:
"\n1234 "
And I need to get - “1234”
But my code doesn't work. Why?
Thanks!!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2016-07-24
@denismatveyev7

Is not

item['num'] = response.xpath('//div/span/text()').extract()[0]
 item = LotItem()

will it be right?
well, in general, it
cuts spaces and translations at the end of the line, and so, and it’s quite possible
item['num'] = response.xpath('//div/span/text()').extract()[0].strip()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question