File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from html .parser import HTMLParser
5
+ from html .entities import name2codepoint
6
+
7
+ class MyHTMLParser (HTMLParser ):
8
+
9
+ def handle_starttag (self , tag , attrs ):
10
+ print ('<%s>' % tag )
11
+
12
+ def handle_endtag (self , tag ):
13
+ print ('</%s>' % tag )
14
+
15
+ def handle_startendtag (self , tag , attrs ):
16
+ print ('<%s/>' % tag )
17
+
18
+ def handle_data (self , data ):
19
+ print (data )
20
+
21
+ def handle_comment (self , data ):
22
+ print ('<!--' , data , '-->' )
23
+
24
+ def handle_entityref (self , name ):
25
+ print ('&%s;' % name )
26
+
27
+ def handle_charref (self , name ):
28
+ print ('&#%s;' % name )
29
+
30
+ parser = MyHTMLParser ()
31
+ parser .feed ('''<html>
32
+ <head></head>
33
+ <body>
34
+ <!-- test html parser -->
35
+ <p>Some <a href=\" #\" >html</a> HTML tutorial...<br>END</p>
36
+ </body></html>''' )
You can’t perform that action at this time.
0 commit comments