首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python的Markaby/Erector

Python的Markaby/Erector
EN

Stack Overflow用户
提问于 2011-01-18 07:49:40
回答 1查看 266关注 0票数 2

我喜欢使用Python,但讨厌编写HTML。有没有一个类似Markaby/Erector的Python模块?

EN

回答 1

Stack Overflow用户

发布于 2011-01-18 10:38:45

看起来你可以用lxml做到这一点:

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

代码语言:javascript
复制
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>")
  )
)

还有一个看起来很相似的Mimsy

代码语言:javascript
复制
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()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4719180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档