Skip to content

Commit b71f8cf

Browse files
author
georg.brandl
committed
Merged revisions 73592,73823 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k ........ r73592 | ezio.melotti | 2009-06-28 00:58:15 +0200 (So, 28 Jun 2009) | 1 line Updated the last example as requested in #6350 ........ r73823 | ezio.melotti | 2009-07-04 03:14:30 +0200 (Sa, 04 Jul 2009) | 1 line #6398 typo: versio. -> version. ........ git-svn-id: http://svn.python.org/projects/python/branches/release31-maint@74391 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 196d2cf commit b71f8cf

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

Doc/library/html.parser.rst

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,23 @@ Example HTML Parser Application
163163
As a basic example, below is a very basic HTML parser that uses the
164164
:class:`HTMLParser` class to print out tags as they are encountered::
165165

166-
from html.parser import HTMLParser
166+
>>> from html.parser import HTMLParser
167+
>>>
168+
>>> class MyHTMLParser(HTMLParser):
169+
... def handle_starttag(self, tag, attrs):
170+
... print("Encountered a {} start tag".format(tag))
171+
... def handle_endtag(self, tag):
172+
... print("Encountered a {} end tag".format(tag))
173+
...
174+
>>> page = """<html><h1>Title</h1><p>I'm a paragraph!</p></html>"""
175+
>>>
176+
>>> myparser = MyHTMLParser()
177+
>>> myparser.feed(page)
178+
Encountered a html start tag
179+
Encountered a h1 start tag
180+
Encountered a h1 end tag
181+
Encountered a p start tag
182+
Encountered a p end tag
183+
Encountered a html end tag
167184

168-
class MyHTMLParser(HTMLParser):
169-
170-
def handle_starttag(self, tag, attrs):
171-
print "Encountered the beginning of a %s tag" % tag
172-
173-
def handle_endtag(self, tag):
174-
print "Encountered the end of a %s tag" % tag
175185

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Installing multiple versions
127127
On Unix and Mac systems if you intend to install multiple versions of Python
128128
using the same installation prefix (--prefix argument to the configure
129129
script) you must take care that your primary python executable is not
130-
overwritten by the installation of a different versio. All files and
130+
overwritten by the installation of a different version. All files and
131131
directories installed using "make altinstall" contain the major and minor
132132
version and can thus live side-by-side. "make install" also creates
133133
${prefix}/bin/python3 which refers to ${prefix}/bin/pythonX.Y. If you intend

0 commit comments

Comments
 (0)