-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinal.py
43 lines (29 loc) · 808 Bytes
/
final.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
import os
import re
from HTMLParser import HTMLParser
f = open("testCollection.dat", 'r')
inRecordingMode = False
class MyHTMLParser(HTMLParser):
def handle_data(self, data):
self.output.append(data)
def feed(self, data):
self.output = []
HTMLParser.feed(self, data)
for line in f:
name = re.search("<title>(.*?)</title>",line)
if name:
parser = MyHTMLParser()
parser.feed(name.group())
a = ''.join(parser.output) + ".txt"
print a
f1 = open(a,'w')
if not inRecordingMode:
if line.startswith('<text>'):
inRecordingMode = True
elif line.startswith('</text>'):
inRecodingMode = False
f1.close()
else:
f1.write(line)
f.close()