2017-10-17 11:48:18 [scrapy.core.engine] INFO: Closing spider (finished)
29957 2017-10-17 11:48:19 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
29958 {'downloader/request_bytes': 2175351,
29959 'downloader/request_count': 6472,
29960 'downloader/request_method_count/GET': 6472,
29961 'downloader/response_bytes': 494012842,
29962 'downloader/response_count': 6472,
29963 'downloader/response_status_count/200': 6419,
29964 'downloader/response_status_count/301': 53,
29965 'dupefilter/filtered': 8,
29966 'finish_reason': 'finished',
29967 'finish_time': datetime.datetime(2017, 10, 17, 11, 48, 19, 59301),
29968 'item_scraped_count': 6417,
29969 'log_count/DEBUG': 12891,
29970 'log_count/ERROR': 1,
29971 'log_count/INFO': 120,
29972 'memusage/max': 385605632,
29973 'memusage/startup': 94334976,
29974 'request_depth_max': 1,
29975 'response_received_count': 6419,
29976 'scheduler/dequeued': 6471,
29977 'scheduler/dequeued/memory': 6471,
29978 'scheduler/enqueued': 6471,
29979 'scheduler/enqueued/memory': 6471,
29980 'spider_exceptions/RuntimeError': 1,
29981 'start_time': datetime.datetime(2017, 10, 17, 9, 55, 15, 21744)}
29982 2017-10-17 11:48:19 [scrapy.core.engine] INFO: Spider closed (finished)
可以看到,我的爬虫其实只爬了6472个,但是实际上读进来的文件里有228336个job要爬,但爬虫却说finish reason:“finished"
贴上代码:
def parse(self, response):
print("number of the id_dict is %s"%len(self.house_id_dict))
for id in self.house_id_dict.keys(): #house ID eg.44225621
yield response.follow("/for-sale/details/"+id, callback=self.parse_house)
print("yield all the links!")
这是一个房地产网站爬虫,我之前抓了20万左右房子的ID号码(记录在了文件里), 然后读取这些ID号(house_id_dict)再次验证这些房子是否更新了信息。也就是说,我让爬虫爬取指定的url请求(url构成是 www.xxx.com/for-sale/details/id号 eg.12345678)
照理来说没错啊,我查了半天,程序也没内存泄漏,不是系统kill的,scrapy为何自己结束了呢?
结束的时候也没执行这行代码,是不是因为队列里任务太多,直接爆了?
print("yield all the links!")
你可以将这个spider类的代码全部粘贴出来,更利于回答者发现问题。
从scrapy的统计日志中可以看出scrapy是正常结束爬取,不是因为队列爆了。所以这里最可能的问题是 self.house_id_dict这个字典中 确实只有6472个key,而你说的20w的key,可能去重后是6472(猜的)
另外,这条语句输出多少呢?