没有项目描述
Online-W3C-Validator的Python项目详细描述
使用W3C在线验证器进行HTML验证的纯Python命令行。 在ci管道中使用它可能非常方便。
安装
pip install -U Online-W3C-Validator
如何使用
您可以使用cli命令:
w3c_validator http://www.google.com some_file.html
示例输出:
INFO:w3c_validator.validator:Files to validate: http://www.google.com INFO:w3c_validator.validator:Number of files: 1 INFO:w3c_validator.validator:validating: http://www.google.com ... error: line 2: CSS: “display”: “inline-box” is not a “display” value in “inline-box” in “.ds”. error: line 2: The “bgcolor” attribute on the “body” element is obsolete. Use CSS instead. error: line 5: Element “nobr” not allowed as child of element “div” in this context. (Suppressing further errors from this subtree.) error: line 5: Attribute “width” not allowed on element “div” at this point. error: line 5: Element “nobr” not allowed as child of element “div” in this context. (Suppressing further errors from this subtree.) error: line 5: The “center” element is obsolete. Use CSS instead. error: line 5: The “clear” attribute on the “br” element is obsolete. Use CSS instead.
或者可以使用包提供的函数validdate 将html文件名或url作为单个参数返回 带有验证输出的json对象。
fromw3c_validatorimportvalidatemessages=validate("http://www.google.com")["messages"]forminmessages:print("Type: %(type)s, Line: %(lastLine)d, Description: %(message)s"%m)
示例输出:
Type: error, Line: 2, Description: CSS: “display”: “inline-box” is not a “display” value in “inline-box” in “.ds”. Type: error, Line: 2, Description: The “bgcolor” attribute on the “body” element is obsolete. Use CSS instead. Type: error, Line: 5, Description: Element “nobr” not allowed as child of element “div” in this context. (Suppressing further errors from this subtree.) Type: error, Line: 5, Description: Attribute “width” not allowed on element “div” at this point. Type: error, Line: 5, Description: Element “nobr” not allowed as child of element “div” in this context. (Suppressing further errors from this subtree.) Type: error, Line: 5, Description: The “center” element is obsolete. Use CSS instead. Type: error, Line: 5, Description: The “clear” attribute on the “br” element is obsolete. Use CSS instead. Type: error, Line: 5, Description: The “align” attribute on the “div” element is obsolete. Use CSS instead. Type: error, Line: 5, Description: Attribute “nowrap” not allowed on element “div” at this point. ...
联系人
对于错误,请使用GitHub issues其他事情请随意 在nad2000@gmail.com联系我。