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

  • SEARCH
  • Home
  • 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 6356379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:56:57+00:00 2026-05-24T22:56:57+00:00

I need to save a file (.pdf) but I’m unsure how to do it.

  • 0

I need to save a file (.pdf) but I’m unsure how to do it. I need to save .pdfs and store them in such a way that they are organized in a directories much like they are stored on the site I’m scraping them off.

From what I can gather I need to make a pipeline, but from what I understand pipelines save “Items” and “items” are just basic data like strings/numbers. Is saving files a proper use of pipelines, or should I save file in spider instead?

  • 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-05-24T22:56:59+00:00Added an answer on May 24, 2026 at 10:56 pm

    Yes and no[1]. If you fetch a pdf it will be stored in memory, but if the pdfs are not big enough to fill up your available memory so it is ok.

    You could save the pdf in the spider callback:

    def parse_listing(self, response):
        # ... extract pdf urls
        for url in pdf_urls:
            yield Request(url, callback=self.save_pdf)
    
    def save_pdf(self, response):
        path = self.get_path(response.url)
        with open(path, "wb") as f:
            f.write(response.body)
    

    If you choose to do it in a pipeline:

    # in the spider
    def parse_pdf(self, response):
        i = MyItem()
        i['body'] = response.body
        i['url'] = response.url
        # you can add more metadata to the item
        return i
    
    # in your pipeline
    def process_item(self, item, spider):
        path = self.get_path(item['url'])
        with open(path, "wb") as f:
            f.write(item['body'])
        # remove body and add path as reference
        del item['body']
        item['path'] = path
        # let item be processed by other pipelines. ie. db store
        return item
    

    [1] another approach could be only store pdfs’ urls and use another process to fetch the documents without buffering into memory. (e.g. wget)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to save a big file, sometime it takes a very long time
I need to save all .xml file names in a directory to a vector.
I need to save some classes and data structures to a file. My first
I'm trying to simply save a file. However, I need a filename entered without
I need to read a file from the local file system using JSP, save
I want to save some custom data into application configuration file and I need
I just need a snippet to open and then save a file. It's an
I have a project where I need to generate a PDF file. Within this
I need to know if there is a way in java/servlet to make documents(doc,pdf)
I have a fairly simple task: I need to read a PDF file and

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.