试图从标题中拆分文本

Trying to split text from title

我想从我的输出中删除这些:我只想要这些 Wave Coffee Collection

'\n\n\t\t3rd Wave Coffee Collection\n\t\t\t\t\n\t'

这是我的代码:

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
            }

            

如果这是您的结果输出:

result = '\n\n\t\t3rd Wave Coffee Collection\n\t\t\t\t\n\t'

然后你可以像这样轻松实现你想要的输出:

result = result.strip()