Recording the total time taken for running a spider in scrapy

前端 未结 3 1978
Happy的楠姐
Happy的楠姐 2021-01-12 17:18

I am using scrapy to scrap a site

I had written a spider and fetched all the items from the page and saved to a csv file, and now i want to save the total exec

3条回答
  •  轮回少年
    2021-01-12 18:08

    This could be useful:

    from scrapy.xlib.pydispatch import dispatcher
    from scrapy import signals
    from scrapy.stats import stats
    from datetime import datetime
    
    def handle_spider_closed(spider, reason):
        print 'Spider closed:', spider.name, stats.get_stats(spider)
        print 'Work time:', datetime.now() - stats.get_stats(spider)['start_time']
    
    
    dispatcher.connect(handle_spider_closed, signals.spider_closed)
    

提交回复
热议问题