Rizwan
Rizwan

Reputation: 13

Strip function is not working. How to solve the problem?

I am trying to remove \r\n from the output in scrapy and I am using strip() function but it's not working. Instead it's giving me the result back with \r\n without any error. Why it's not working and How could I solve this problem?

def Regional_category(self, response):
    items = response.meta['items']
    names = {'name1':'Site Description'}
    finder = {'finder1': '.site-descr::text}
    for name, find in zip(names.values(), finder.values()):
        items[name] = response.css(find.strip()).extract()
        yield items

Upvotes: 1

Views: 272

Answers (1)

warvariuc
warvariuc

Reputation: 59644

I think this should do it:

items[name] = response.css(find).extract().strip()

You were stripping the CSS selector, not the result.

If the result is a list of strings:

items[name] = list(map(str.strip, response.css(find).extract()))

Upvotes: 1

Related Questions