Skip to content

Commit c4da0b5

Browse files
pablohoffmandangra
authored andcommitted
extended documentation on how to access crawler stats from extensions
1 parent d52c188 commit c4da0b5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

docs/topics/stats.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ opened when the spider is opened, and closed when the spider is closed.
2929
Common Stats Collector uses
3030
===========================
3131

32-
Access the stats collector throught the :attr:`~scrapy.crawler.Crawler.stats`
33-
attribute::
32+
Access the stats collector through the :attr:`~scrapy.crawler.Crawler.stats`
33+
attribute. Here is an example of an extension that access stats::
3434

35-
@classmethod
36-
def from_crawler(cls, crawler):
37-
stats = crawler.stats
35+
class ExtensionThatAccessStats(object):
36+
37+
def __init__(self, stats):
38+
self.stats = stats
39+
40+
@classmethod
41+
def from_crawler(cls, crawler):
42+
return cls(crawler.stats)
3843

3944
Set stat value::
4045

0 commit comments

Comments
 (0)