Last active
August 24, 2017 23:00
-
-
Save sananth12/5afa14f25e6e669a7e0c to your computer and use it in GitHub Desktop.
Reddit r/images scraper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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