2
我正在使用代理池来抓取网站。他们中很少人速度很快,但很少代理很慢,这让我想知道是否有任何方法来检测中间件中抓取网页的速度(scrapedPages/minute),以便我可以丢弃较慢的代理。如何获得scrapy的抓取速度?
我可以看到日志级别INFO
在屏幕上每分钟后打印此速度。
2015-12-04 11:28:50 [scrapy] INFO: Crawled 10 pages (at 10 pages/min), scraped 10 items (at 10 items/min)
但我无法在中间件中获得这个速度。这是迄今为止我尝试过的。
class getSpeedstats(object):
def __init__(self, stats):
self.stats = stats
@classmethod
def from_crawler(cls, crawler):
return cls(crawler.stats)
def process_request(self, request, spider):
print self.stats.get_stats()
上面的代码给了我这样的输出:
{'log_count/DEBUG': 784, 'scheduler/dequeued': 408, 'log_count/INFO': 10, 'downloader/response_count': 392, 'downloader/response_status_count/200': 392, 'response_received_count': 392, 'scheduler/enqueued/memory': 408, 'downloader/response_bytes': 3209679, 'start_time': datetime.datetime(2015, 12, 4, 3, 48, 41, 31403), 'scheduler/dequeued/memory': 408, 'scheduler/enqueued': 408, 'downloader/request_bytes': 101321, 'downloader/request_method_count/GET': 407, 'downloader/request_count': 407, 'item_scraped_count': 391}
{'log_count/DEBUG': 786, 'scheduler/dequeued': 409, 'log_count/INFO': 11, 'downloader/response_count': 393, 'downloader/response_status_count/200': 393, 'response_received_count': 393, 'scheduler/enqueued/memory': 409, 'downloader/response_bytes': 3217865, 'start_time': datetime.datetime(2015, 12, 4, 3, 48, 41, 31403), 'scheduler/dequeued/memory': 409, 'scheduler/enqueued': 409, 'downloader/request_bytes': 101575, 'downloader/request_method_count/GET': 408, 'downloader/request_count': 408, 'item_scraped_count': 392}
但我还是无法破译我如何通过这个计算蜘蛛的速度。任何人都可以告诉我是否有其他方式做这件事?
感谢。这清除了几个疑问。 'datetime(2015,12,4,9,27,45,718073)'代码表示什么?它是否在当前日期时间前1分钟?或者蜘蛛的开始时间? – Rahul
对不起,我是'stats.start_time' – eLRuLL
获取零作为输出,直到响应数超过分钟。 – Rahul