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

Python 获取下载文件的大小

程序员文章站 2022-03-02 12:40:43
...
# -*- coding: utf-8 -*-

from urlparse import urlparse

url = "http://im.baidu.com/download/BaiduHi_2.4_Beta.exe"
parsedurl = urlparse(url)
net_loc = parsedurl[1]
path = parsedurl[2]
httpConn = httplib.HTTPConnection(net_loc);
httpConn.request("GET", path)
r = httpConn.getresponse()
if r.status == 200:
    size = r.getheader('Content-Length')
    size = int(size) / 1024
    print 'size:', size
    print r.getheader('Content-Type')       #类型   
    print r.getheader('Last-Modified')      #修改时间   
else:
    print r.status, r.reason

httpConn.close()

转载于:https://www.cnblogs.com/leavingme/archive/2009/08/17/1548220.html