I have a working BaseSpider on Scrapy 0.20.0. But I'm trying to collect the number of found website URL's and print it as INFO when the spider is finished (closed). Problem is that I am not able to print this simple integer variable at the end of the session, and any print statement in the parse()
or parse_item()
functions are printed too early, long before.
I also looked at this question, but it seem somewhat outdated and it is unclear how to use it, properly. I.e. Where to put it (myspider.py, pipelines.py etc)?
Right now my spider-code is something like:
class MySpider(BaseSpider):
...
foundWebsites = 0
...
def parse(self, response):
...
print "Found %d websites in this session.\n\n" % (self.foundWebsites)
def parse_item(self, response):
...
if item['website']:
self.foundWebsites += 1
...
And this is obviously not working as intended. Any better and simple ideas?