2011-01-17 4 views
2

私はPythonを使うのが好きですが、HTMLを書くのは嫌です。 PythonのMarkaby/Erectorのようなモジュールはありますか?また、同様のようだMimsyありMarkaby/Erector for Python

http://lxml.de/lxmlhtml.html#creating-html-with-the-e-factory

from lxml.html import builder as E 
from lxml.html import usedoctest 
html = E.HTML(
    E.HEAD(
    E.LINK(rel="stylesheet", href="great.css", type="text/css"), 
    E.TITLE("Best Page Ever") 
), 
    E.BODY(
    E.H1(E.CLASS("heading"), "Top News"), 
    E.P("World News only on this page", style="font-size: 200%"), 
    "Ah, and here's some more text, by the way.", 
    lxml.html.fromstring("<p>... and this is a parsed fragment ...</p>") 
) 
) 

:あなたは一種のlxmlのでこれを行うことができますように

答えて

1

は思えます。

import makeHTML 
pageTitle = 'Hello World' 
pageHead = makeHTML.part('head') 
pageHead.addPart('title', content=pageTitle) 
pageBody = makeHTML.part('body') 
pageBody.addPart('h1', content=pageTitle) 
pageBody.addPart('p', content="Oh no, not again!") 
pageBody.addPart('hr') 
fullPage = makeHTML.part('html') 
fullPage.addPiece(pageHead) 
fullPage.addPiece(pageBody) 
fullPage.make()