Python 我想让Scrapy把每一项都检查一遍

Python 我想让Scrapy把每一项都检查一遍,python,web-scraping,web-crawler,scrapy,scrapy-spider,Python,Web Scraping,Web Crawler,Scrapy,Scrapy Spider,我希望Scrapy对每个项目进行一次检查,以便将相关数据分组在一起。因为它只是把所有的链接,标题,日期等放在一起。它还多次将所有内容发布到该文件中。我对Scrapy和Python都是新手,所以如果有任何建议,我将不胜感激 这是我的蜘蛛代码: from scrapy.spiders import Spider from scrapy.selector import Selector from fashioBlog.functions import extract_data from fashi

我希望Scrapy对每个项目进行一次检查,以便将相关数据分组在一起。因为它只是把所有的链接,标题,日期等放在一起。它还多次将所有内容发布到该文件中。我对Scrapy和Python都是新手,所以如果有任何建议,我将不胜感激

这是我的蜘蛛代码:

from scrapy.spiders import Spider 
from scrapy.selector import Selector
from fashioBlog.functions import extract_data

from fashioBlog.items import Fashioblog

class firstSpider(Spider):
   name = "first"
   allowed_domains = [
      "stopitrightnow.com"

   ]
   start_urls = [
      "http://www.stopitrightnow.com"

   ]




def parse(self, response):
    sel = Selector(response)
    sites = sel.xpath('//div[@class="post-outer"]')
    items= []

    for site in sites:
        item = Fashioblog()

        item['title'] = extract_data(site.xpath('//h3[normalize-space(@class)="post-title entry-title"]//text()').extract())
        item['url'] = extract_data(site.xpath('//div[normalize-space(@class)="post-body entry-content"]//@href').extract())
        item['date'] = extract_data(site.xpath('//h2[normalize-space(@class)="date-header"]/span/text()').extract())
        #item['body'] = site.xpath('//div[@class="post-body entry-content"]/i/text()').extract()
        item['labelLink'] = extract_data(site.xpath('//span[normalize-space(@class)="post-labels"]//@href').extract())
        item['comment'] = extract_data(site.xpath('//span[normalize-space(@class)="post-comment-link"]//text()').extract())
        item['picUrl'] = extract_data(site.xpath('//div[normalize-space(@class)="separator"]//@href').extract())
        #item['labelText'] = extract_data(site.xpath('(//i//text()').extract())
        #item['labelLink2'] = extract_data(site.xpath('(//i//@href').extract())
        yield item

在表达式前面加上一个点,使其与上下文相关:

item['title'] = extract_data(site.xpath('.//h3[normalize-space(@class)="post-title entry-title"]//text()').extract())
                                         ^ HERE

是否检查项目管道功能以跳过重复项?你能举个例子说明你在寻找什么吗?好的,这样数据的排序方式更好地反映了网站,这就是我想要的,谢谢。是否有办法组织数据,使其更易于阅读?目前,每一段数据都被附加到下一段数据中,因此这是一个混乱的局面。我们可以从“extract_data”函数中看到代码吗?不知道它在做什么。从xpath中提取文本不需要这些。还可以尝试在开始时将//更改为所需xpath表达式的结尾处//或从结尾处//更改为所需的xpath表达式。