Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
f99e4b5d
Kaydet (Commit)
f99e4b5d
authored
Eki 28, 2011
tarafından
Ezio Melotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Improve HTMLParser example in the doc and fix a couple minor things.
üst
f50ffa94
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
23 deletions
+19
-23
html.parser.rst
Doc/library/html.parser.rst
+19
-23
No files found.
Doc/library/html.parser.rst
Dosyayı görüntüle @
f99e4b5d
...
...
@@ -101,9 +101,9 @@ An exception is defined as well:
.. method:: HTMLParser.handle_startendtag(tag, attrs)
Similar to :meth:`handle_starttag`, but called when the parser encounters an
XHTML-style empty tag (``
<
a
...
/>
``). This method may be overridden by
XHTML-style empty tag (``
<
img
...
/>
``). This method may be overridden by
subclasses which require this particular lexical information; the default
implementation simpl
e
calls :meth:`handle_starttag` and :meth:`handle_endtag`.
implementation simpl
y
calls :meth:`handle_starttag` and :meth:`handle_endtag`.
.. method:: HTMLParser.handle_endtag(tag)
...
...
@@ -178,27 +178,23 @@ An exception is defined as well:
Example HTML Parser Application
-------------------------------
As a basic example, below is a very basic HTML parser that uses the
:class:`HTMLParser` class to print out tags as they are encountered::
>>> from html.parser import HTMLParser
>>>
>>> class MyHTMLParser(HTMLParser):
... def handle_starttag(self, tag, attrs):
... print("Encountered a {} start tag".format(tag))
... def handle_endtag(self, tag):
... print("Encountered a {} end tag".format(tag))
...
>>> page = """
<html><h1>
Title
</h1><p>
I'm a paragraph!
</p></html>
"""
>>>
>>> myparser = MyHTMLParser()
>>> myparser.feed(page)
Encountered a html start tag
Encountered a h1 start tag
Encountered a h1 end tag
Encountered a p start tag
Encountered a p end tag
Encountered a html end tag
As a basic example, below is a simple HTML parser that uses the
:class:`HTMLParser` class to print out start tags, end tags, and data
as they are encountered::
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print("Encountered a start tag:", tag)
def handle_endtag(self, tag):
print("Encountered an end tag:", tag)
def handle_data(self, data):
print("Encountered some data:", data)
parser = MyHTMLParser()
parser.feed('
<html><head><title>
Test
</title></head>
'
'
<body><h1>
Parse me!
</h1></body></html>
')
.. rubric:: Footnotes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment