scrapy:找到具有特定文本的元素

时间:2017-03-23 05:16:24

标签: python web-scraping scrapy scrapy-spider

我正在使用scrapy来爬行。我正在全面了解网站。

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()

现在我正在搜索一个文本,我可以通过python通过简单的搜索文本/子字符串获取。我想要的是选择该文本匹配的选择器。请告诉我们最好的方法是什么。

1 个答案:

答案 0 :(得分:5)

你可以这样做。

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

这将使用抓取的值和选择器打印出整个对象。

相关问题