Skip to content

Instantly share code, notes, and snippets.

@sananth12
Last active August 24, 2017 23:00
Show Gist options
  • Save sananth12/5afa14f25e6e669a7e0c to your computer and use it in GitHub Desktop.
Save sananth12/5afa14f25e6e669a7e0c to your computer and use it in GitHub Desktop.
Reddit r/images scraper
import urllib
import requests
import bs4 as BS
h={'User-Agent': 'Mozilla/5.0'}
url='http://reddit.com/r/pics'
r=requests.get(url, headers=h)
soup=BS.BeautifulSoup(r.text)
imgs=soup.select('a.thumbnail.may-blank')
links = [i['href'] for i in imgs]
n=0
for l in links:
urllib.urlretrieve(l,"img"+str(n)+".jpg")
n=n+1
print "Downloaded %d images" % n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment