Created
May 15, 2013 00:14
-
-
Save toumorokoshi/5580763 to your computer and use it in GitHub Desktop.
Small scraper for project365photos
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
from BeautifulSoup import BeautifulSoup | |
import urllib2 | |
import requests | |
import re | |
import os | |
photo_url_match = re.compile("^http://.*photos.*amazonaws.*photos.*png") | |
target_directory = "/tmp/" | |
html = urllib2.urlopen("YOURIPHONEPROJECT_URL_HERE").read() | |
parsed = BeautifulSoup(html) | |
links = parsed.findAll("a") | |
def download_file(url, output_url): | |
r = requests.get(url) | |
target_path = os.path.join(target_directory, output_url) | |
print "Downloading %s to %s..." % (url, target_path) | |
with open(target_path, "w+") as image: | |
image.write(r.content) | |
i = 1 | |
for l in links: | |
if l.get('class') == "lightbox": | |
download_file(l.get('href'), "%s.png" % str(i)) | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment