Created
May 18, 2012 05:53
-
-
Save imflop/2723446 to your computer and use it in GitHub Desktop.
grab photo
This file contains 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
#-*- coding:utf-8 -*- | |
#!/usr/bin/env python | |
import os | |
import sys | |
import urllib2 | |
from BeautifulSoup import BeautifulSoup as bs | |
def download(u): | |
soup = bs(urllib2.urlopen(u)) | |
for image in soup.findAll("a"): | |
#print "Image: %(href)s" % image | |
filename = image["href"].split('/')[-1] | |
try: | |
url_str = urllib2.urlopen(u + filename) | |
fl = open(filename, 'wb') | |
file_size = 0 | |
block_size = 8192 | |
while True: | |
buffer = url_str.read(block_size) | |
if not buffer: | |
break | |
file_size += len(buffer) | |
fl.write(buffer) | |
fl.close() | |
except Exception, e: | |
print e | |
def main(): | |
url = 'http://miss29.ru/uploads/all_foto/' | |
#photo_folder = '/photo/' | |
download(url) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment