欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

获得下载文件的大小(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()
相关标签: Python