您的位置:首页 > 编程语言 > Python开发

python使用md5处理下载图片

2015-04-30 23:48 531 查看
import urllib2
import hashlib

opener = urllib2.build_opener()

req = opener.open("http://avatar.csdn.net/E/5/5/2_sdjtwenzhihao.jpg")
meta = req.info()
file_size = int(meta.getheaders("Content-Length")[0])
content_type = meta.getheaders('Content-Type')[0].split(';')[0]
print file_size, content_type

#D3E373E8E47E785CC2C0997E3D1A4BBC
#d3e373e8e47e785cc2c0997e3d1a4bbc
md5=hashlib.md5(req.read()).hexdigest()
print(md5)
#save the file
#open("2_sdjtwenzhihao.jpg", 'wb').write(req.read())
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: