python分析日志

需求1:分析日志每天的的访问量

日志格式:
95.143.192.110 - - [15/Dec/2019:10:22:00 +0800] “GET /post/nihao/ HTTP/1.1” 304 0 “https://www.ssgeek.com/” "Mozilla/5.0 "

dict = {}
with open('log2.txt','r') as f:
  for line in f.readlines():
    time = line.split()[3][1:12]
    if time not in list(dict.keys()):
      dict[time] = 1
    else:
      dict[time] += 1


for key,values in dict.items():
  print("{} : {}".format(key,values))

需求2:分析指定用户每分钟内访问量

日志格式:
23:56:17 Amy

dest_time="12:10"
dest_name="Amy"
n=0
with open('log.txt','r') as f:
  for line in f.readlines():
    if len(line) >= 10:
      time = line.split()[0]
      name = line.split()[1]
      #print("{},{}".format(name,name.find("ac")))      
      if dest_time == time[0:5] and name == dest_name:
        n = n + 1
print(" jack vist time in one minute  is : {} ".format(n))
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值