Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrapy : find element which has particular text

I am using scrapy to crawl. I am getting whole content of website.

import scrapy
import os

class QuotesSpider(scrapy.Spider):
    name = "team"

    def start_requests(self):
        yield scrapy.Request(url='http://*****.com', callback=self.get_scripts)

    def get_scripts(self, response):
        print response.css("body").extract()

    def get_scripts(self, response):
        print response.css("body").extract()

Now i am searching for a text, which i can get by simple search text/sub-string by python. What i want is to select that selector where this text match. Please let know what is the best way to do this.

like image 890
Pritam Parua Avatar asked Mar 23 '17 05:03

Pritam Parua


1 Answers

You can do something like this.

response.xpath("//*[contains(text(), 'MY TEXT')]").getall()

It will return list of all items containing MY TEXT

like image 183
Umair Ayub Avatar answered Oct 03 '22 08:10

Umair Ayub