Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51440
| Date | 2013-07-29 15:14 +0300 |
|---|---|
| From | Burak Arslan <burak.arslan@arskom.com.tr> |
| Subject | Re: Generating HTML |
| References | <CACQBTrRunN4_22iLkge_hzz5e7cytBiee3281TgJiZ+h3dWOEA@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5230.1375100541.3114.python-list@python.org> (permalink) |
Hi,
On 07/29/13 14:41, Morten Guldager wrote:
> Something like:
> table_struct = ['table', ['tr', ['td', {class=>"red"}, "this is
> red"],['td', {class=>"blue"}, "this is not red"]]]
> html = struct2html(table_struct)
>
> Suggestions?
>
See: http://lxml.de/lxmlhtml.html#creating-html-with-the-e-factory
Python 2.7.5 (default, Jul 16 2013, 00:38:32)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml.html.builder import E
>>> e = E.html(
... E.head(
... E.title("Sample Html Page")
... ),
... E.body(
... E.div(
... E.h1("Hello World"),
... E.p(
... "lxml is quite nice when it comes to generating HTML "
... "from scratch"
... ),
... id="container",
... )
... )
... )
>>> from lxml.html import tostring
>>> print tostring(e, pretty_print=True)
<html>
<head><title>Sample Html Page</title></head>
<body><div id="container">
<h1>Hello World</h1>
<p>lxml is quite nice when it comes to generating HTML from scratch</p>
</div></body>
</html>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Generating HTML Burak Arslan <burak.arslan@arskom.com.tr> - 2013-07-29 15:14 +0300
csiph-web