python从Route Views Archieve上下载解析.bz2数据包
1.下载压缩包
2.解压缩包
3.解析解压缩后文件
import os
import requests
import urllib
import urllib2
import bz2
url = 'http://archive.routeviews.org/bgpdata/2001.10/RIBS/rib.20011026.1648.bz2'
f_del=open('/root/python-file-download/ribs.bz2', "r+")
f_del.truncate()
print "emptying file successful!"
urllib.urlretrieve(url,'/root/python-file-download/ribs.bz2')
print "downloading sucessful!"
print ""
f='/root/python-file-download/ribs.bz2'
f_del=open('/root/python-file-download/ribs', "r+")
f_del.truncate()
print "emptying decompression file is successful!"
zipfile = bz2.BZ2File(f)
data = zipfile.read()
newfilepath='/root/python-file-download/ribs'
open(newfilepath, 'wb').write(data)
print "decompression is successful!"
print ""
f_del=open('/root/python-file-download/ribs.txt',"r+")
f_del.truncate()
print "emptying analyzing file is successful!"
os.system("bgpdump '/root/python-file-download/ribs.bz2' > '/root/python-file-download/ribs.txt' ")
print "analyzing file is successful!"
知识补充
URL
Internet上的每一个网页都具有一个唯一的名称标识,通常称之为URL(Uniform Resource Locator, 统一资源定位器)。它是www的统一资源定位标志,简单地说URL就是web地址,俗称“网址”。
|