在Python中验证(X)HTML [英] Validate (X)HTML in Python

查看:263
本文介绍了在Python中验证(X)HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

验证文档是否遵循一些HTML版本(我可以指定的优先级),最好的方法是什么?我希望能够知道失败发生的位置,例如在基于Web的验证器中,本地Python应用除外。

解决方案

XHTML很简单,使用 lxml



HTML比较难,因为在HTML群体中传统上没有那么多的验证兴趣(通过验证器,yikes运行StackOverflow本身)。最简单的解决方案是执行外部应用程序,例如 nsgmls OpenJade ,然后解析它们的输出。


What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.

解决方案

XHTML is easy, use lxml.

HTML is harder, since there's traditionally not been as much interest in validation among the HTML crowd (run StackOverflow itself through a validator, yikes). The easiest solution would be to execute external applications such as nsgmls or OpenJade, and then parse their output.

这篇关于在Python中验证(X)HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆