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


Groups > comp.lang.python > #51440

Re: Generating HTML

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <burak.arslan@arskom.com.tr>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '"this': 0.03; 'see:': 0.07; 'cc:addr:python-list': 0.11; 'python': 0.11; '"from': 0.16; 'from:addr:arskom.com.tr': 0.16; 'from:addr:burak.arslan': 0.16; 'from:name:burak arslan': 0.16; 'message-id:@arskom.com.tr': 0.16; 'received:arskomhosting.com': 0.16; 'scratch': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'quite': 0.32; 'something': 0.35; 'hi,': 0.36; 'generating': 0.39; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'world': 0.66; 'sample': 0.67; 'jul': 0.74; '2013,': 0.91
Date Mon, 29 Jul 2013 15:14:48 +0300
From Burak Arslan <burak.arslan@arskom.com.tr>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130711 Thunderbird/17.0.7
MIME-Version 1.0
To Morten Guldager <morten.guldager@gmail.com>
Subject Re: Generating HTML
References <CACQBTrRunN4_22iLkge_hzz5e7cytBiee3281TgJiZ+h3dWOEA@mail.gmail.com>
In-Reply-To <CACQBTrRunN4_22iLkge_hzz5e7cytBiee3281TgJiZ+h3dWOEA@mail.gmail.com>
X-Enigmail-Version 1.5.2
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5230.1375100541.3114.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375100541 news.xs4all.nl 15900 [2001:888:2000:d::a6]:45285
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51440

Show key headers only | View raw


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


Thread

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

csiph-web