python练习 根据日志中的ip和url排序
2016-07-29 15:04
357 查看
#!/usr/bin/env python #coding:utf-8 def open_file(file_name): res={} with open(file_name) as f: for line in f: tmp=line.split(' ') # print tmp ip,url=tmp[0],tmp[6] # print ip,url 以元组的形式存到列表中 res[(ip,url)]=res.get((ip,url),0)+1 return sorted(res.items(),key=lambda x:x[1],reverse=True) #print open_file('log1.log') def get_htmlstr(arr): #拼接字符串 tmp1='<tr><td>Num%s</td> <td>%s</td> <td>%s</td> <td>%s</td></tr>' html_str='<table border="1px">'+tmp1%('名次','IP','URL','COUNT') for index,value in enumerate(arr[:10]): html_str+='<tr><td>Num%s</td> <td>%s</td> <td>%s</td> <td>%s</td></tr>' %(index,value[0][0],value[0][1],value[1]) html_str+='</table>' return html_str def write_html(file_name): res=open_file(file_name) with open('res2.html','w') as f: f.write(get_htmlstr(res)) write_html('log1.log')
相关文章推荐
- python学习 根据日志中的ip和url排序
- python分析nginx日志根据共性url屏蔽ip
- 学习练习程序:根据日期提取日志的python脚本。
- python 分析 nginx 日志 ip 并存入sqlite 数据库
- python根据域名循环遍历查找绑定IP
- Python基于nginx访问日志并统计IP访问量
- Python基于nginx访问日志并统计IP访问量 推荐
- python 分析 nginx 日志 ip 并存入sqlite 数据库
- python统计日志ip访问数的方法
- python脚本实现统计日志文件中的ip访问次数代码分享
- python脚本实现统计日志文件中的ip访问次数代码分享
- python基于nginx访问日志统计客户端ip访问量
- 本文以python实现了一个日志文件中ip提取与统计程序
- 海量日志数据提取出访问次数最多的那个IP python实现 总结
- python或hive根据ip快速计算地域分布的算法
- 根据访问日志封IP
- python统计日志ip访问数脚本
- 海量日志,提取出现最多的IP--python实现
- python 脚本统计squid日志中的IP访问数和URL访问数量
- python脚本统计日志独立ip