您的位置:首页 > 理论基础 > 计算机网络

python获取网络文件信息

2013-12-23 12:17 363 查看
import urllib2

url = 'http://cidian.youdao.com/download/YoudaoDict.exe'
usock = urllib2.urlopen(url)
lastModified = usock.info().get('Last-Modified')  #last modified time
#补充一下,这个是此网页的修改时间,即此文件的最后上传时间
size =  usock.info().get('Content-Length')
if size is None:
size = 0
size = float(size) # in bytes
sizeK = size / 1024.0 # in KB (Kilo Bytes)
sizeM = sizeK / 1024.0 # in MB (Mega Bytes)

print "Last Modified: ",lastModified
print "Size: %.0f bytes"%size
print "Size: %.3f KB"%sizeK
print "Size: %.3f MB"%sizeM

fileName = url.split('/')[-1]
print "Filename: %s"%fileName


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: