Created
January 18, 2013 07:55
-
-
Save cloudaice/4563029 to your computer and use it in GitHub Desktop.
download_picture
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-*- | |
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