Mohamad Zidani
Mohamad Zidani

Reputation: 23

How to scrape only text?

Code :

import scrapy

class BlogSpider(scrapy.Spider):
    name = 'bijouterie'
    start_urls = ['https://www.example.com']

    def parse(self, response):
        for post in response.css('#engine-results .drs'):
            yield {'title': post.css('a.moodalbox.response').get()}

Run Command (Windows 10) :

scrapy runspider C:\Users\DELL\Desktop\icscrape\bijouterie.py -o posts.csv

The CSV File : https://pastebin.com/qEQTKEcC

I want to scrape only the text not the entire html class code.

Upvotes: 0

Views: 218

Answers (1)

Ayush
Ayush

Reputation: 26

Just add (::text) at the end of your css selector like

{'title': post.css('a.moodalbox.response::text').get()}

Upvotes: 1

Related Questions