Skip to content

Instantly share code, notes, and snippets.

@cloudaice
Created January 18, 2013 07:55
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 cloudaice/4563029 to your computer and use it in GitHub Desktop.
Save cloudaice/4563029 to your computer and use it in GitHub Desktop.
download_picture
#-*-coding:utf-8-*-
from BeautifulSoup import BeautifulSoup
import requests
from PIL import Image
from StringIO import StringIO
r = requests.get('http://www.xiaomi.com')
assert(r.status_code == 200)
soup = BeautifulSoup(r.text)
urls = soup.findAll('img')
for url in urls:
src = None
if url.has_key('src'):
src = url['src']
if url.has_key('src2'):
src = url['src2']
r = requests.get(src)
try:
image_name = src.split('/')[-1].strip()
fd = open(image_name,'w')
fd.write(r.content)
except:
print src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment