Getting the most popular pages from your Apache logfile

An Apache logfile can be huge and hard to read.

Here is a way to get a list of the most visited pages (or files) from an Apache logfile.

In this example, we only want to know the URLs from GET requests. We will use the wonderful Counter which is in Python's Collections

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()

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,507评论 0 23
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,107评论 19 139
  • 此去余年三两空,一世浮喧终为梦。 仙山琼阁藏何处? 唯剩吾心问道情!
    idea新世界阅读 1,288评论 0 0
  • 刚刚因为找不到东西而焦头烂额,上楼下楼跑了两趟结果什么也没发现。 昨晚因为妹妹春游所以带上我爸一起去华润万家找了点...
    矛盾患者阅读 832评论 0 0
  • 1@ 公司里放眼望去,清一色的单身女青年们,她们背着LV,用着香奈儿,一年两次国际游。她们早晨用星巴克来提神...
    细踝骨阅读 2,784评论 0 0

友情链接更多精彩内容