请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

从Apache日志文件中获取访问量最大的页面(Top)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Apache日志文件可能很庞大且难以阅读。
这里提供一种从Apache日志文件中获取访问量最大的页面(或文件)列表的方法。

在此示例中,我们只需要知道GET请求中的URL。编程实现将使用Python的集合中强大的Counter计数器


import collections

logfile = open("yourlogfile.log", "r")

clean_log=[]

for line in logfile:
    try:
        # copy the URLS to an empty list.
# We get the part between GET and HTTP clean_log.append(line[line.index("GET")+4:line.index("HTTP")]) except: pass counter = collections.Counter(clean_log) # get the Top 50 most popular URLs for count in counter.most_common(50): print(str(count[1]) + " " + str(count[0])) logfile.close()

 

参考资料

  • Getting the most popular pages from your Apache logfile

鲜花

握手

雷人

路过

鸡蛋
专题导读
上一篇:
Google命令行脚本发布时间:2022-05-14
下一篇:
JavaScript编程常见问题集锦【四】发布时间:2022-05-14
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap