Skip to content

Instantly share code, notes, and snippets.

@mgnisia
Last active October 27, 2023 10:06
Show Gist options
  • Save mgnisia/d6b479dd8e58764a2ace2c99c8139181 to your computer and use it in GitHub Desktop.
Save mgnisia/d6b479dd8e58764a2ace2c99c8139181 to your computer and use it in GitHub Desktop.
Python File to batch download pdfs from a website
import requests
from bs4 import BeautifulSoup as soup
import os
# Define Website to Download pdf
url = 'website to download pdfs'
# Get Website content
r = requests.get(url)
# Create soup object of requests object
soup = soup(r.text, 'html.parser')
# Loop through all elements of the website with the tag a
for link in soup.find_all('a'):
# Download pdf if the name pdf is in the hyperlink and
# is not a None Object
if link.get('href') is not None and '.pdf' in link.get('href'):
# Download pdf with wget
os.system('wget '+ link.get('href'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment