简体   繁体   中英

How to remove \r\n from language prices?

When I run the code, it gives me \\r\\n with space. I have tried to remove \\r\\n from the result but it didn't. This is code. Please check it out.

def parse_subtitles(self, response):
    items = FetchingItem()
    Arabic_price = response.css('.row:nth-child(1) .item-container:nth-child(1) .rate::text').extract()
    Chinese_price = response.css('.row:nth-child(1) .item-container:nth-child(2) .rate::text').extract()

    names_list = ['Arabic_price', 'Chinese_price']
    for names in names_list:
        result = [re.sub('\r\n\s+', ' ', text) for text in names]

    items['Arabic_price'] = Arabic_price
    items['Chinese_price'] = Chinese_price

    yield items

Not sure what do you want exactly but this code works:

def parse_subtitles(self, response):
    results = {}

    results['Arabic_price'] = response.css('.row:nth-child(1) .item-container:nth-child(1) .rate::text').extract()
    results['Chinese_price'] = response.css('.row:nth-child(1) .item-container:nth-child(2) .rate::text').extract()

    names_list = ['Arabic_price', 'Chinese_price']
    for name in names_list:
        results[name] = [re.sub(r'[\r\n\s]+', ' ', text) for text in results[name]]

    items['Arabic_price'] = results['Arabic_price']
    items['Chinese_price'] = results['Chinese_price']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM