这个例子比较简单,就当是练练手。
#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
结果展示