如何使用regex-Python打印具有GET-between时间范围的行

2024-09-28 19:28:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我的日志文件在下面。需要找到在2018-07-11 10和2018-07-11 11之间运行的线路

2018-07-11 10:12:06 12.115.14.240 "PUT /apng/assembler-2.0/assembler2.php HTTP/1.1" 403 231 "http://littlesvr.ca/apng/history.html" 2018-07-11 10:15:06 202.167.250.99 "GET /apng/images/o_sample.png?142475198 HTTP/1.1" 403 115656 "http://bbs.mydigit.cn/read.php" 2018-07-11 11:16:06 120.115.144.240 "GET /apng/assembler-2.0/assembler2.php HTTP/1.1" 200 231 "http://littlesvr.ca/apng/history.html"

with open(log) as f:
    log = f.read()
    ###if condition to show to get GET
          line = re.search(rx,log)

期望输出 2018-07-11 10:15:06 202.167.250.99 "GET /apng/images/o_sample.png?142475198 HTTP/1.1" 403 115656 "http://bbs.mydigit.cn/read.php"


Tags: sampleloghttpreadgethtmlhistoryca