我尝试为一个大的日志文件创建一个过滤器,比如
Fri Oct 5 00:55:45 2012 [pid 2766] CONNECT: Client "157.82.250.217"
Fri Oct 5 00:55:45 2012 [pid 2765] [ftp] OK LOGIN: Client "157.82.250.217", anon password "mozilla@example.com"
Fri Oct 5 00:56:05 2012 [pid 2767] [ftp] FAIL DOWNLOAD: Client "157.82.250.217", "/pub/10.5524/100001_101000/100036/Gene_catalogue/Gene_catalogue.pep", 1638400 bytes, 81.81Kbyte/sec
Fri Oct 5 00:57:27 2012 [pid 3056] CONNECT: Client "157.82.250.217"
Fri Oct 5 00:57:27 2012 [pid 3055] [ftp] OK LOGIN: Client "157.82.250.217", anon password "-wget@"
我想把ip地址放到http://www.ip-adress.com中以获得组织名称 例如157.82.250.217-->;东京大学然后在ip地址后面添加东京大学
网站是http://www.ip-adress.com/ip_tracer/157.XX.xxx.xx 源代码如下:
<th>ISP of this IP [<a href="/isp" target="_self">?</a>]:</th>
<td>
University of Tokyo</td>
</tr>
<tr class="odd">
<th>Organization:</th>
<td>
University of Tokyo</td>
</tr>
<tr class="even">
我是python的新手,我为filter time编写了一些代码,您能帮我在里面添加函数吗
import time
f= open("/opt/CLiMB/Storage1/log/vsftp.log")
def OnlyRecent(line):
if time.strptime(line.split("[")[0].strip(),"%a %b %d %H:%M:%S %Y")> time.gmtime(time.time()-(60*60*24*7)):
return True
return False
filename= time.strftime('%Y%m%d')+'.log'
f1= open(filename,'w')
for line in f:
if OnlyRecent(line):
print line
f1.write(line)
f.close()
f1.close()
谢谢!!你知道吗
我(通常没有人在StackOverflow)会写你的代码。看看http://docs.python.org/library/urllib2.html。构建您的url,将其传递给
urllib2.urlopen
,并将结果读入字符串。然后提取你想要的数据。就这样!你知道吗在您的例子中,简单的字符串操作应该足以提取数据,但是您也可以检查http://www.crummy.com/software/BeautifulSoup/。你知道吗
相关问题 更多 >
编程相关推荐