python [解析python中的nginx访问日志]解析python #log中的nginx访问日志

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python [解析python中的nginx访问日志]解析python #log中的nginx访问日志相关的知识,希望对你有一定的参考价值。

def seg_access_log(line):
    delimiters = {'[': ']', '"': '"'}
    idx, start, count, delimiter, results = 0, 0, len(line), ' ', []

    while 1:
        idx = line.find(delimiter, start)
        delimiter = ' '  # reset
        if idx < 0:
            break

        if start < idx:
            results.append(line[start:idx])
        start = idx + 1
        # if idx != count - 1 and line[idx + 1] in delimiters:
        if line[idx + 1] in delimiters:
            delimiter = delimiters[line[idx + 1]]
            start += 1

    if start < count:
        results.append(line[start:].rstrip())

    return results

以上是关于python [解析python中的nginx访问日志]解析python #log中的nginx访问日志的主要内容,如果未能解决你的问题,请参考以下文章

深入解析Python中的线程同步方法

使用python控制nginx禁封ip

python nginx - 用python统计访问量技巧

python脚本分析nginx访问日志

nginx站点目录及文件URL访问控制

python脚本分析Nginx的每个IP的访问次数