php - python怎么捕捉日志文件里面的UA
本文介绍了php - python怎么捕捉日志文件里面的UA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
日志格式如下
`61.182.137.6 - - [21/Apr/2017:00:00:37 +0800] 0 "HEAD / HTTP/1.1" 200 - "-" "Baidu-YunGuanCe-SLABot(ce.baidu.com)"
123.125.71.89 - - [21/Apr/2017:00:00:38 +0800] 0 "GET /article/515140 HTTP/1.1" 200 10315 "-" "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/s...)"
216.244.66.229 - - [21/Apr/2017:00:00:39 +0800] 0 "GET /article/330012 HTTP/1.1" 200 29593 "-" "Mozilla/5.0 (compatible; DotBot/1.1; http://www.opensiteexplorer.o... help@moz.com)"`
python3.5用什么方式可以捕捉到UA里面的蜘蛛类型Baiduspider和DotBot
要怎么写
解决方案
filename = 'xxx.log'
with open(a) as f:
for i in f:
print(re.findall('(?<=compatible; )([^/]+)', i))
这篇关于php - python怎么捕捉日志文件里面的UA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文