diff options
| author | Sam Manzi <manzi.sam@gmail.com> | 2016-12-03 10:35:13 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-12-03 10:35:13 +1100 |
| commit | e1a17cfbab33eeaeefa0a239419134270271d095 (patch) | |
| tree | 506629b579fff4f53faed08c151fdc7db47d2994 /doc/tutorial.txt | |
| parent | 12589e1db4704bffcd28191e29b8e827d989d908 (diff) | |
| download | python-lxml-e1a17cfbab33eeaeefa0a239419134270271d095.tar.gz | |
Show real output and add example etree.HTML
Diffstat (limited to 'doc/tutorial.txt')
| -rw-r--r-- | doc/tutorial.txt | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/doc/tutorial.txt b/doc/tutorial.txt index 71f3a5d7..3d51e1ea 100644 --- a/doc/tutorial.txt +++ b/doc/tutorial.txt @@ -686,7 +686,7 @@ serialisation is ASCII: UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' ... >>> etree.tostring(root, method='text', encoding="UTF-8") - b'HelloW\xc3\xb6rld' + b'HelloWörld' Here, serialising to a Python unicode string instead of a byte string might become handy. Just pass the name ``'unicode'`` as encoding: @@ -807,6 +807,14 @@ commonly used to write XML literals right into the source: There is also a corresponding function ``HTML()`` for HTML literals. +.. sourcecode:: pycon + + >>> root = etree.HTML("<root>data</root>") + >>> print(root.tag) + root + >>> etree.tostring(root) + b'<html><body><root>data</root></body></html>' + The parse() function -------------------- |
