擅长:python、mysql、java
<p>我从<a href="http://docs.python.org/library/htmlparser.html#example-html-parser-application" rel="nofollow">docs</a>扩展了示例:</p>
<pre><code>from HTMLParser import HTMLParser
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print "Encountered the beginning of a %s tag" % tag
def handle_endtag(self, tag):
print "Encountered the end of a %s tag" % tag
def handle_data(self, data):
print "Encountered data %s" % data
p = MyHTMLParser()
p.feed('<p>test</p>')
</code></pre>
<p>-</p>
<pre><code>Encountered the beginning of a p tag
Encountered data test
Encountered the end of a p tag
</code></pre>