Skip to content

Instantly share code, notes, and snippets.

@arafsheikh
Created April 29, 2017 12:44
Show Gist options
  • Save arafsheikh/1171563aed7620b044150e5774a8c418 to your computer and use it in GitHub Desktop.
Save arafsheikh/1171563aed7620b044150e5774a8c418 to your computer and use it in GitHub Desktop.
Download all PDF files in a webpage
from mechanize import Browser
from bs4 import BeautifulSoup
URL = ""
br = Browser()
res = br.open(URL)
soup = BeautifulSoup(res.read())
a = soup.find_all('a')
for link in a:
link = link['href']
if '.pdf' in link:
urllib.urlretrieve(link, "Lesson " + count)
count += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment