下面是使用urllib2下载图像的示例代码:
for photo in getListOfPhotos('Anouk'):
with open(photo[0]+'.jpg','w+') as f:
response = urllib2.urlopen(photo[1])
answer = response.read()
while answer:
f.write(answer)
f.flush()
answer = response.read()
(假设photo
是列表,其中第一项是文件名,第二项是链接)
但我得到了破碎的图片(有绿线,红场等)。怎么了?
发布于 2014-08-23 14:43:53
您可以使用urllib.urlretrieve
下载图像,将图像url和directory/name_to_save_as
作为第二个参数传递。
import urllib
urllib.urlretrieve(image_url,"locataion_to_save")
https://stackoverflow.com/questions/25463035
复制相似问题