from subprocess import Popen PIPE import sys import re LIMIT pattern s

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from subprocess import Popen, PIPE
import sys
import re
LIMIT = 3
pattern = sys.argv[1]
re_pattern = re.compile(re.escape(pattern), re.I)
url = sys.argv[2]
data = Popen(["lynx", "-dump", url], stdout=PIPE).communicate()[0]
lines = []
for line in data.splitlines():
if re_pattern.search(line):
lines.append(line)
if len(lines) == LIMIT:
break
print '\n'.join(lines)