在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/人工智能  數(shù)據(jù)分析&挖掘  Python/ scrapy 爬蟲(chóng)關(guān)閉但實(shí)際任務(wù)并沒(méi)完成

scrapy 爬蟲(chóng)關(guān)閉但實(shí)際任務(wù)并沒(méi)完成

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)

可以看到,我的爬蟲(chóng)其實(shí)只爬了6472個(gè),但是實(shí)際上讀進(jìn)來(lái)的文件里有228336個(gè)job要爬,但爬蟲(chóng)卻說(shuō)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!")

這是一個(gè)房地產(chǎn)網(wǎng)站爬蟲(chóng),我之前抓了20萬(wàn)左右房子的ID號(hào)碼(記錄在了文件里), 然后讀取這些ID號(hào)(house_id_dict)再次驗(yàn)證這些房子是否更新了信息。也就是說(shuō),我讓爬蟲(chóng)爬取指定的url請(qǐng)求(url構(gòu)成是 www.xxx.com/for-sale/details/id號(hào) eg.12345678)
照理來(lái)說(shuō)沒(méi)錯(cuò)啊,我查了半天,程序也沒(méi)內(nèi)存泄漏,不是系統(tǒng)kill的,scrapy為何自己結(jié)束了呢?
結(jié)束的時(shí)候也沒(méi)執(zhí)行這行代碼,是不是因?yàn)殛?duì)列里任務(wù)太多,直接爆了?

print("yield all the links!")
回答
編輯回答
鹿惑

你可以將這個(gè)spider類的代碼全部粘貼出來(lái),更利于回答者發(fā)現(xiàn)問(wèn)題。

從scrapy的統(tǒng)計(jì)日志中可以看出scrapy是正常結(jié)束爬取,不是因?yàn)殛?duì)列爆了。所以這里最可能的問(wèn)題是 self.house_id_dict這個(gè)字典中 確實(shí)只有6472個(gè)key,而你說(shuō)的20w的key,可能去重后是6472(猜的)

print("number of the id_dict is %s"%len(self.house_id_dict))

另外,這條語(yǔ)句輸出多少呢?

2017年1月27日 11:42
編輯回答
小曖昧

我也是遇到了同樣的問(wèn)題 ,請(qǐng)問(wèn)是怎么解決的嗎?明明是一直循環(huán)的, 加了很多異常檢測(cè), 但是還是任務(wù)完成,查看日志只有
[<twisted.python.failure.Failure twisted.internet.error.ConnectionLost: Connection to the other side was lost in a non-clean fashion: Connection lost.>]

2018年2月19日 16:18
編輯回答
不討囍

有可能是讀取進(jìn)來(lái)的ID存在不規(guī)范。

例如第6473個(gè)ID不規(guī)范,則scrapy在此時(shí)報(bào)錯(cuò),而繼續(xù)爬取之前的網(wǎng)頁(yè)。這樣最后scrapy就算正常finished

2018年3月20日 11:39