关闭早期的Scrapy蜘蛛

时间:2017-09-28 12:40:03

标签: python web-scraping scrapy

我编写了一个蜘蛛来刮网站contorion.de。代码运行并从页面中提取我想要的内容,但在1700条记录的早期关闭,而它应该刮掉整个网站大约300,000条记录。这是代码:

import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor

class ContorionSpider(CrawlSpider):
    name = 'contorion'
    allowed_domains = ['contorion.de']
    start_urls = ['https://www.contorion.de',]

    rules = (
        Rule(LinkExtractor(deny = (r'\/c-',r'\/marke',r'\/search',r'\/bg-bau',r'\/shopping-list',r'\/branchenkataloge',r'\/kontakt',r'\/faq',r'\/versandkosten',r'\/agb',r'\/profistore',r'\/umwelt',r'\/gutschein',r'\/magazin',r'\/login',r'\/impressum',r'\/presse',r'\/team',r'\/jobs',r'\/sitemap','.*aktion.*')), callback='parse_item', follow=True),
        )
    def parse_item(self, response):
        if response.css("div").re_first('(?<=itemprop="name")(?s)(.*$)') is not None:
            yield {
            'name': response.css("div").re_first('(?<=itemprop="name")(?s)(.*$)'),
            'price': response.css("div").re_first('(?<=meta itemprop="price")(?s)(.*$)')
            }
        else:
            for n in response.xpath("//div[@class='product-staple__list-item']").extract():
                yield{
                'namePrice': n
                }

这是结束日志:

2017-09-28 13:36:06 [scrapy.core.engine] INFO: Closing spider (finished)
2017-09-28 13:36:06 [scrapy.extensions.feedexport] INFO: Stored json feed (1778 items) in: output.json
2017-09-28 13:36:06 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 277641,
 'downloader/request_count': 663,
 'downloader/request_method_count/GET': 663,
 'downloader/response_bytes': 35623314,
 'downloader/response_count': 663,
 'downloader/response_status_count/200': 633,
 'downloader/response_status_count/301': 11,
 'downloader/response_status_count/302': 13,
 'downloader/response_status_count/400': 6,
 'dupefilter/filtered': 13008,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2017, 9, 28, 12, 36, 6, 620000),
 'httperror/response_ignored_count': 6,
 'httperror/response_ignored_status_count/400': 6,
 'item_scraped_count': 1778,
 'log_count/DEBUG': 2466,
 'log_count/INFO': 16,
 'offsite/domains': 23,
 'offsite/filtered': 5671,
 'request_depth_max': 8,
 'response_received_count': 639,
 'scheduler/dequeued': 662,
 'scheduler/dequeued/memory': 662,
 'scheduler/enqueued': 662,
 'scheduler/enqueued/memory': 662,
'start_time': datetime.datetime(2017, 9, 28, 12, 33, 45, 703000)}
2017-09-28 13:36:06 [scrapy.core.engine] INFO: Spider closed (finished)

我不确定我的拒绝规则是否过于模糊,或者我是否需要更改某些设置才能下载更多内容?

0 个答案:

没有答案