跑Monkey时可能会产生大量日志如果一个一个找的话又太浪费时间所以通过Python编写了一段代码来查找需要的关键字如果没有我们想要的关键字就完全没有必要再去将日志翻一遍了
exc [Touch,CRASH,ANR,died] # 要查找的关键字with open(C:\\Users\\monkey_01.txt, encodingutf-8) as f: if os.path.exists(copy.txt): with open(copy.txt,r) as f2: # 清空文件res f2.readlines()print(res)f2.seek(0)f2.truncate()with open(copy.txt, at) as f1: f1.write(崩溃日志\n)dic_key {}for key in exc:dic_key[key] 0for line in f:for key in exc:if key in line:dic_key[key] dic_key[key] line.count(key)# print(line)with open(copy.txt,at) as f:f.write(line)# print(dic_key)with open(copy.txt,at) as f: # 写入文件f.write("分析结果\n")f.write("------------------------------\n")for key, value in dic_key.items() :f.write("关键字{}出现的次数{}\n".format(key, value))
转:https://www.cnblogs.com/jiablogs/p/11134438.html
【本文转自:海外高防服务器 http://www.558idc.com/krgf.html 欢迎留下您的宝贵建议】