用Python连续解析文件 [英] Continuously Parse file in Python
问题描述
我正在编写一个脚本,该脚本使用HTTP通信量行分析文件,并取出域,当前仅将它们打印到屏幕上.我正在使用httpry连续将流量写入文件.这是我用来删除域名的脚本
I'm writing a script that parses a file with HTTP traffic lines, and takes out the domains and currently just prints them to the screen. I'm using httpry to continuously write the traffic to a file. Here is the script I'm using to strip out the domain names
#!/usr/bin/python
import re
input = open("results.txt","r")
for line in input:
domain = line.split()[6]
if domain != "-":
print domain
尽管此脚本很好用,但我想一种连续运行此脚本的方法,以便在将新流量添加到输入文件时,该脚本能够将其删除.我不能只在httpry的输出上运行awk,因为我最终要将这些域输入到Mongo数据库中,并且我也需要脚本来执行该操作.如果有人可以给我一些想法,如何在输出中持续运行此python脚本,而不重印以前的条目,将不胜感激.谢谢.
While this script works great, I'd like a way to continuously run this script so that as new traffic gets added to the input file, the script is able to strip it out. I can't just run awk on the output of httpry, as I'm eventually going to be entering these domains into a Mongo database, and I'll need the script to do that as well. If anyone could give me some ideas how to constantly run this python script on the output, but not reprint previous entries, it would be much appreciated. Thanks.
推荐答案
尝试在 查看全文