search

Home  >  Q&A  >  body text

想写一个python分析统计apache 日志文件的脚本

想写一个python分析统计apache 网站日志文件并将统计后的数据存入mysql中的的脚本,有没有参考的,没有思路
主要是统计 哪些url被爬取了 及 被爬取次数,以及IP这两个

PHP中文网PHP中文网2794 days ago619

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:36:55

    First normalize the original data, then set the key value yourself, then use the Counter of collections to count, and then traverse and write it to the db. The approximate code is as follows:

    data = ['/a 1.2.1.2', '/b 2.2.2.2', '/c 1.1.1.1', '/d 2.2.2.2', '/d 2.2.2.2']
    from collections import Counter
    c = Counter(data)
    print c
    Counter({'/d 2.2.2.2': 2, '/b 2.2.2.2': 1, '/a 1.2.1.2': 1, '/c 1.1.1.1': 1})

    You can also maintain the dictionary yourself, the key is: /PATH:IP or something, you can set it yourself, and then just add it while traversing it

    reply
    0
  • Cancelreply