Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51440 > unrolled thread

Re: Generating HTML

Started byBurak Arslan <burak.arslan@arskom.com.tr>
First post2013-07-29 15:14 +0300
Last post2013-07-29 15:14 +0300
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Generating HTML Burak Arslan <burak.arslan@arskom.com.tr> - 2013-07-29 15:14 +0300

#51440 — Re: Generating HTML

FromBurak Arslan <burak.arslan@arskom.com.tr>
Date2013-07-29 15:14 +0300
SubjectRe: Generating HTML
Message-ID<mailman.5230.1375100541.3114.python-list@python.org>
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>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web