python下载图片到本地

这个例子比较简单,就当是练练手。

#coding:utf-8
import requests
imgUrl = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1488283814900&di=02f17fc81be4dff70cc8ed54fc5c7719&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fbaike%2Fpic%2Fitem%2F3bf33a87e950352a344d78d55643fbf2b2118b3b.jpg"   #请求图片的url
imgresponse = requests.get(imgUrl, stream=True)   #以流的方式打开
image = imgresponse.content
address="E:\pythonimages"+"\\"   #保存地址
try:
    with open(address+"code.jpg" ,"wb") as jpg: 
        jpg.write(image)
except IOError:
    print("IO Error\n")
finally:
    jpg.close

结果展示

《python下载图片到本地》

    原文作者:csdn侠
    原文地址: https://blog.csdn.net/qq_22222499/article/details/58608003
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞