0
我有這條管道在我scrapy,我需要得到一個信息從Scrapy統計無法獲取值從Scrapy統計字典
class MyPipeline(object):
def __init__(self, stats):
self.stats = stats
@classmethod
def from_crawler(cls, crawler):
return cls(crawler.stats)
def process_item(self, item, spider):
print self.stats.get_stats()['item_scraped_count']
return item
當我運行代碼,我得到這個錯誤
Traceback (most recent call last):
File "D:\Kerja\HIT\PYTHON~1\SMARTE~1\SMARTE~1\lib\site-packages\twisted\internet\defer.py", line 649, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "D:\Kerja\HIT\Python Projects\Smarter Sorting\smarter_sorting\smarter_sorting\smarter_sorting\pipelines.py", line 35, in process_item
print self.stats.get_stats()['item_scraped_count']
KeyError: 'item_scraped_count'
如果這不是獲得統計值的正確方法,那麼我該怎麼做?
開始。 –