Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8189921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:26:45+00:00 2026-06-07T03:26:45+00:00

Hi i am using scrapy to scrape the sites I had written spider,fetched all

  • 0

Hi i am using scrapy to scrape the sites

I had written spider,fetched all the information and saved in to csv files through pipeline.py

pipeline.py code

class Examplepipeline(object):

    def __init__(self):
        dispatcher.connect(self.spider_opened, signal=signals.spider_opened)
        dispatcher.connect(self.spider_closed, signal=signals.spider_closed)

    def spider_opened(self, spider):
        log.msg("opened spider  %s at time %s" % (spider.name,datetime.now().strftime('%H-%M-%S')))
        self.exampledotcomCsv = csv.writer(open("csv's/%s(%s).csv"% (spider.name,datetime.now().strftime("%d/%m/%Y,%H-%M-%S")), "wb"),
                   delimiter=',', quoting=csv.QUOTE_MINIMAL)
        self.exampledotcomCsv.writerow(['field1', 'field2','field3','field4'])           

    def process_item(self, item, spider):
            log.msg("Processsing item " + item['title'], level=log.DEBUG)
            self.brandCategoryCsv.writerow([item['field1'].encode('utf-8'),
                                    [i.encode('utf-8') for i in item['field2']],
                                    item['field3'].encode('utf-8'),
                                    [i.encode('utf-8') for i in item['field4']]
                                    ])
            return item 


    def spider_closed(self, spider):
        log.msg("closed spider %s at %s" % (spider.name,datetime.now().strftime('%H-%M-%S')))

In the above code i can able to get start time and end time of spider, but after closing the spider i want to calculate and display the total time taken by spider that is difference between start time and end time
So how can i do that, we can write this functionality in spider_closed method?

Please let me know this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:26:47+00:00Added an answer on June 7, 2026 at 3:26 am

    Why not:

    def spider_opened(self, spider):
        spider.started_on = datetime.now()
        ...
    
    def spider_closed(self, spider):
        work_time = datetime.now() - spider.started_on
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using scrapy to scrap a site I had written a spider and
I'm trying to scrape pages using a Scrapy spider and then save those pages
I'm using PHP to scrape a website and collect some data. It's all done
I want to scrape Groupon deals using Nokogiri. I want to scrape all these
I'm using the HTML agility pack to scrape a website. I'm looking though all
I am using Prowser to screen scrape internal corporate websites. Some of the sites
I am using scrapy to crawl different sites, for each site I have an
I am trying to parse sitemap.xml files using scrapy, the sitemap files are like
I'm trying to scrape a website using some regex. But the site isn't written
I am trying to scrape some information of a page using the jsdom.env function.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.