Scrapy, a fast high-level web crawling & scraping framework for Python.
Add __str__ method on stats collector class (#2746)
Paul Tremberth2a7c54943632
diff --git a/scrapy/statscollectors.py b/scrapy/statscollectors.pyindex faeedb74d..1827c2230 100644--- a/scrapy/statscollectors.py+++ b/scrapy/statscollectors.py@@ -105,7 +105,7 @@ class StatsCollector:"""Called when the spider is closed."""if self._dump:logger.info(- "Dumping Scrapy stats:\n" + pprint.pformat(self._stats),+ f"Dumping Scrapy stats:\n{self}",extra={"spider": self._crawler.spider},)self._persist_stats(self._stats)@@ -113,6 +113,9 @@ class StatsCollector:def _persist_stats(self, stats: StatsT) -> None:pass+ def __str__(self) -> str:+ return pprint.pformat(self._stats)+class MemoryStatsCollector(StatsCollector):"""A simple stats collector that keeps the stats of the last scraping run