VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-scrape-all-pdf-files-in-a-website/

⇱ How to Scrape all PDF files in a Website? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Scrape all PDF files in a Website?

Last Updated : 23 Jul, 2025

Prerequisites: Implementing Web Scraping in Python with BeautifulSoup

Web Scraping is a method of extracting data from the website and use that data for other uses. There are several libraries and modules for doing web scraping in Python.  In this article, we'll learn how to scrape the PDF files from the website with the help of beautifulsoup, which is one of the best web scraping modules in python, and the requests module for the GET requests. Also, for getting more information about the PDF file, we use PyPDF2 module.

Step by Step Code -

Step 1: Import all the important modules and packages.

Step 2: Passing the URL and make an HTML parser with the help of BeautifulSoup.

In the above code:

  • Scraping is done by the https://www.geeksforgeeks.org/python/how-to-extract-pdf-tables-in-python/ link
  • requests module is used for making get request
  • read.content is used to go through all the HTML code. Printing will output the source code of the web page.
  • soup is having HTML content and used to parse the HTML

Step 3: We need to traverse through the PDFs from the website.

 
 

Output:

👁 Image

In the above code:

  • list_of_pdf is an empty set created for adding all the PDF files from the web page. Set is used because it never repeats the same-named elements. And automatically get rid of duplicates.
  • Iteration is done within all the links converting the .HTML to .pdf. It is done as the PDF name and HTML name has an only difference in the format, the rest all are same.
  • We use the set because we need to get rid of duplicate names. The list can also be used and instead of add, we append all the PDFs.


 Step 4: Create info function with pypdf2 module for getting all the required information of the pdf.

 
 In the above code: 

  • Info function is responsible for giving all the required scraped output inside of the PDF.
  • io.BytesIO(response.content) - It is used because response.content is a binary code and the requests library is quite low leveled and generally compiled (not interpreted). So to handle byte, io.BytesIO is used.
  • There are several pypdfs2 functions to access different data in pdf.


 Note: Refer Working with PDF files in Python for detailed information.

Complete Code:

Output:

👁 Image
Comment