2 def find_all_tags(content
, tag
):
4 def find_next_tag_start(content
, tag
, start
=0):
8 if content
[start
] != '<':
12 while i
< l
and start
+1+i
< lc
:
13 if content
[start
+1+i
] != tag
[i
]: break
15 if i
== l
and start
+1+i
< lc
and content
[start
+1+i
] in tag_end
:
20 def find_next_tag_end(content
, tag
, start
=0):
22 i
= content
.find(s
, start
)
26 def find_next_tag(content
, tag
, start
=0):
27 s
= find_next_tag_start(content
, tag
, start
)
28 if s
== -1: return (-1, -1)
29 e
= find_next_tag_end(content
, tag
, s
+1+len(tag
))
30 if e
== -1: return (-1, -1)
35 s
,e
= find_next_tag(content
, tag
, start
)
40 if __name__
== '__main__':
42 with
open(sys
.argv
[1], "r") as h
:
44 for a
in find_all_tags(s
, 'a'):