#encoding=utf-8
'''
Created on Dec 7, 2011
@author: cooler
'''
import urllib2
import urllib
import os
imagepath=["http://hdn.xnimg.cn/photos/hdn221/20110528/1145/tiny_QKbC_85482j019118.jpg"]
def cd(path):
try:
os.mkdir(path)
os.chdir(path)
return 0
except:
return 1
#download images
def image_down(path,list_image):
cd(path)
if not list_image:
print "no img"
else:
for image in list_image:
try:
urllib.urlretrieve(image,image.split('/')[-1]) #利用image.split('/')[-1]获得文件名
print "save : "+image+" success !"
except:
print "save : "+image+" failure and continue...."
#调用图片下载函数
image_down("C:/img",imagepath)
python 下载网页图片
最新推荐文章于 2024-03-18 14:35:56 发布