FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
learn-python3/samples/commonlib/use_htmlparser.py at master · sofay/learn-python3 · GitHub
sofay
/
learn-python3
Public
forked from
michaelliao/learn-python3
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
learn-python3
/
samples
/
commonlib
/
use_htmlparser.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
36 lines (26 loc) · 811 Bytes
Breadcrumbs
learn-python3
/
samples
/
commonlib
/
use_htmlparser.py
Copy path
File metadata and controls
executable file
·
36 lines (26 loc) · 811 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from
html
.
parser
import
HTMLParser
from
html
.
entities
import
name2codepoint
class
MyHTMLParser
(
HTMLParser
):
def
handle_starttag
(
self
,
tag
,
attrs
):
print
(
'<%s>'
%
tag
)
def
handle_endtag
(
self
,
tag
):
print
(
'</%s>'
%
tag
)
def
handle_startendtag
(
self
,
tag
,
attrs
):
print
(
'<%s/>'
%
tag
)
def
handle_data
(
self
,
data
):
print
(
data
)
def
handle_comment
(
self
,
data
):
print
(
'<!--'
,
data
,
'-->'
)
def
handle_entityref
(
self
,
name
):
print
(
'&%s;'
%
name
)
def
handle_charref
(
self
,
name
):
print
(
'&#%s;'
%
name
)
parser
=
MyHTMLParser
()
parser
.
feed
(
'''<html>
<head></head>
<body>
<!-- test html parser -->
<p>Some <a href=
\"
#
\"
>html</a> HTML tutorial...<br>END</p>
</body></html>'''
)
Back
|
FazBrowse Home
|
New Git URL