Skip to content
Advertisement

Trying to split text from title

I want to remove these from my output: I want these only Wave Coffee Collection

'nntt3rd Wave Coffee Collectionnttttnt'

This is my code :

from scrapy.http import Request
import scrapy
class PushpaSpider(scrapy.Spider):
    name = 'pushpa'
    start_urls = ['https://onepagelove.com/inspiration']
    

    def parse(self, response):
        books = response.xpath("//div[@class='thumb-image']//a//@href").extract()
        for book in books:
            absolute_url = response.urljoin(book)
            yield Request(absolute_url, callback=self.parse_book)

    def parse_book(self, response):
        title = response.xpath("//span[@class='review-name']//h1//text()").extract_first()
        


        yield{
            'title':title
            }

            

Advertisement

Answer

If this is your resulting output:

result = 'nntt3rd Wave Coffee Collectionnttttnt'

Then you can easily achieve your desired output like this:

result = result.strip()
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement