gpt4 book ai didi

python - 用于 Python 的 Markaby/Erector

转载 作者:太空宇宙 更新时间:2023-11-03 16:37:59 24 4
gpt4 key购买 nike

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

最佳答案

看起来你可以用 lxml 来做这个:

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>")
)
)

还有Mimsy这看起来很相似。

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()

关于python - 用于 Python 的 Markaby/Erector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4719180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com