支持 DOM 访问的最 Pythonic XHTML/HTML 解析器/生成器/模板模块是什么?
它应该能够以高度面向对象的方式创建、修改和读取 X/HTML DOM 很像,但并不臃肿,而且确实是Pythonic。 最好它也能处理格式错误的 HTML,但对于模板我们可以跳过这个。
例如,我想这样做:
>> from someAmazingTemplate import *
>> html = Template('<html><head><title>Hi</title></head><body></body></html>')
>> html.head.append('<link type="text/css" href="main.css" rel="stylesheet" />')
>> html.head.title
Hi
>> html['head']['title']
Hi
我应该能够使用/定义短函数并像这样使用它们:
>> html.head.append(stylesheet(href="main.css"))
>> html.body.append(h1('BIG TITLE!12',Class="roflol"))
>> html.body.SOURCE
<body>
<h1 class="roflol">
BIG TITLE!12
</h1>
</body>
注意:如果它不存在,我将在 BSD/MIT/Python 许可证下制作它。非常欢迎帮助。 任何有助于 Pythonic Web 应用程序开发的事情都会很棒。 非常感谢!
——卢克·斯坦利
It should be able to create, modify and read X/HTML in a highly object oriented way that still feels DOM like but is not obese, and is really Pythonic.
Preferably it would deal with malformed HTML too, but we can skip this for templates.
For example, I'd like to do this:
>> from someAmazingTemplate import *
>> html = Template('<html><head><title>Hi</title></head><body></body></html>')
>> html.head.append('<link type="text/css" href="main.css" rel="stylesheet" />')
>> html.head.title
Hi
>> html['head']['title']
Hi
I should be able to use/define short functions and use them like this:
>> html.head.append(stylesheet(href="main.css"))
>> html.body.append(h1('BIG TITLE!12',Class="roflol"))
>> html.body.SOURCE
<body>
<h1 class="roflol">
BIG TITLE!12
</h1>
</body>
Note: If it doesn't exist, I'm going to make it under BSD/MIT/Python license. Help is most welcome.
Anything that works towards more Pythonic web app development will be great.
Very much appreciate it!
-Luke Stanley
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一部分大部分可以由 ElementTree 完成,但它需要更多步骤:
第二部分可以通过创建 Element 对象来完成,但您需要做一些自己的工作才能使其按照您真正想要的方式发生:
您可以创建一个
stylesheet
你自己的功能:以及整个文档:
但是,我认为如果你最终要编写自己的东西,那么这是一个很好的起点。 ElementTree 非常强大。
编辑:我意识到这可能不正是您正在寻找的内容。我只是想提供一些东西作为可用的替代方案,并证明它实际上可以在不需要太多工作的情况下完成。
The first part can for the most part be done by ElementTree, but it takes a few more steps:
The second part can be completed by creating Element objects, but you'd need to do some of your own work to make it happen the way you really want:
You could create a
stylesheet
function of your own:And the whole document:
But, I think if you're going to end up writing your own thing, this is a good place to start. ElementTree is very powerful.
Edit: I realize that this is probably not exactly what you're looking for. I just wanted to provide something as an available alternative and to also prove that it could actually be done without too much work.
Amara Bindery 提供了我见过的最 Pythonic XML API。请参阅快速参考、手册 和 常见问题解答
Amara Bindery provides the most Pythonic XML API I've seen. See the quick reference, manual and faq