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())