获得下载文件的大小(Python)
程序员文章站
2022-02-22 20:21:51
...
>>> import urlparse
>>> import httplib
>>> parsedurl = urlparse.urlparse('http://vfile.home.news.cn/music/public/vd06/200907/23/4a/MUfs0620090723163313524a2f29.mp3')
>>> httpConn = httplib.HTTPConnection(parsedurl[1])
>>> httpConn.request('GET', parsedurl[2])
>>> response = httpConn.getresponse()
>>> if response.status == 200:
... size = response.getheader('Content-Length')
... size = int(size) / 1024
... print 'Size: %s KB,Content-Type: %s, Last-Modified: %s'%(size,response.getheader('Content-Type'),response.getheader('Last-Modified'))
... else:
... print response.status,response.reason
>>> httpConn.close()
上一篇: 简单小例子,拷贝文件读输入
下一篇: boostrap图片(裁剪固定尺寸)上传