-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathremove tags.py
More file actions
44 lines (31 loc) · 860 Bytes
/
remove tags.py
File metadata and controls
44 lines (31 loc) · 860 Bytes
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
44
def remove_tags(s):
text_list = []
text = []
if '<' not in s:
return s.split()
while s:
if s[0] == '<':
s = s[s.find('>')+1:]
else:
if '<' not in s:
text = s.split()
text_list = text_list + text
return text_list
else:
text = s[:s.find('<')].split()
text_list = text_list + text
s = s[s.find('>')+1:]
return text_list
s1 = '''<h1>Title</h1><p>This is a
<a href="http://www.udacity.com">link</a>.<p>'''
print remove_tags(s1)
s2 = '''<table cellpadding='3'>
<tr><td>Hello</td><td>World!</td></tr>
</table>'''
print remove_tags(s2)
s3 = "<hello><goodbye>"
print remove_tags(s3)
s4 = "This is plain text."
print remove_tags(s4)
s5 = "<br />This line starts with a tag"
print remove_tags(s5)