-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyhtml.py
More file actions
31 lines (21 loc) · 732 Bytes
/
Copy pathmyhtml.py
File metadata and controls
31 lines (21 loc) · 732 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
#!/usr/bin/python
# coding:utf-8
from HTMLParser import HTMLParser
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print('1 <%s>' % tag)
def handle_endtag(self, tag):
print('2 </%s>' % tag)
def handle_startendtag(self, tag, attrs):
print('3 <%s/>' % tag)
def handle_data(self, data):
print('4 data')
def handle_comment(self, data):
print('5 <!-- -->')
def handle_entityref(self, name):
print('6 &%s;' % name)
def handle_charref(self, name):
print('7 &#%s;' % name)
parser = MyHTMLParser()
parser.feed(
'<html><head></head><body><p>Some <a href=\"#\">html</a> tutorial...<br>END')