是否可以从scrapy的调度程序队列中删除请求?我有一个工作例程,限制爬行到某个域一段时间。它的工作方式是,一旦达到时间限制,它就不会再产生链接了,但是因为队列已经包含了数千个域的请求,所以我希望一旦达到时间限制就将它们从调度程序队列中删除。< / p>
答案 0 :(得分:1)
好的,所以我最终听完了@rickgh12hs的建议并编写了我自己的Downloader Middleware:
from scrapy.exceptions import IgnoreRequest
import tldextract
class clearQueueDownloaderMiddleware(object):
def process_request(self, request, spider):
domain_obj = tldextract.extract(request.url)
just_domain = domain_obj.registered_domain
if(just_domain in spider.blocked):
print "Blocked domain: %s (url: %s)" % (just_domain, request.url)
raise IgnoreRequest("URL blocked: %s" % request.url)
spider.blocked是一个类列表变量,其中包含阻止的域,阻止从被阻止的域中进一步下载。似乎工作得很好,赞成@rickgh12hs!