Skip to content

Instantly share code, notes, and snippets.

@imflop
Created May 18, 2012 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imflop/2723446 to your computer and use it in GitHub Desktop.
Save imflop/2723446 to your computer and use it in GitHub Desktop.
grab photo
#-*- 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