使用Python爬取一张图片并且保存下来
首先找一张图片
要下载的图片
1. 获取图片
def downlaodPicture(url):
response = requests.get(url)
if response.status_code == 200:
return response.content
2. 保存图片
def savePicture(content):
path = os.getcwd() + '/' + md5(content).hexdigest() + '.jpg'
if not os.path.exists(path):
with open(path, 'wb') as f:
f.write(content)
f.close()
3. 调用程序
if __name__ == '__main__':
url = 'http://img0.dili360.com/pic/2018/09/26/5bab38dfd80333y53304453_t.jpg@!rw9'
content = downlaodPicture(url)
savePicture(content)