在scrapy中,调用crawler.engine.crawl()会绕过限制机制吗?

时间:2014-10-31 14:12:05

标签: scrapy

为了给出一些背景知识,我正在编写一个蜘蛛,它在RabbitMQ主题上侦听蜘蛛的新URL。当它从队列中提取URL时,它会通过调用crawler.engine.crawl(request)将其添加到爬网队列中。我已经注意到,如果我将200个网址放入队列(全部为同一个域),我有时会得到超时,但是如果我通过start_urls属性添加200个网址,则不会发生这种情况。

所以我想知道在通过crawler.engine.crawl()添加网址时是否适用正常的限制机制(每个域的并发请求,延迟等)?

这是一个小代码示例:

    @defer.inlineCallbacks
    def read(self, queue_object):
        # pull a url from the RabbitMQ topic
        ch,method,properties,body = yield queue_object.get()
        if body:
            req = Request(url=body)
            log.msg('Scheduling ' + body + ' for crawl')
            self.crawler.engine.crawl(req, spider=self)
        yield ch.basic_ack(delivery_tag=method.delivery_tag)

1 个答案:

答案 0 :(得分:0)

它不会绕过DownloaderMiddlewaresDownloader。他们直接绕过Scheduler

转到SpiderMiddlewares

Source

IMO您应该使用SpiderMiddleware使用process_start_requests覆盖spider.start_requests