W3C Command-line Validator

Apr 29, 2011 pythonvalidatorW3C

A command-line script (written in Python) for validating HTML and CSS files and URLs using the WC3 validators.

The w3c-validator.py script uses the curl(1) command to submit HTML files and URLs to the W3C Markup Validation Service and CSS files and URLs to the W3C CSS Validation Service. The script parses and reports the JSON results returned by the validators.

Note: Currently the CSS validator’s JSON output option is experimental and not formally documented.

You can find the source on GitHub at https://github.com/srackham/w3c-validator

Usage

The script command syntax is:

python w3c-validator.py [--verbose] FILE|URL...

Examples (w3c-validator is just a convenient symbolic link in the shell PATH to the executable w3c-validator.py script):

$ w3c-validator tests/data/testcases-html5.html
validating: tests/data/testcases-html5.html ...
error: line 822: The tt element is obsolete. Use CSS instead.
error: line 829: The tt element is obsolete. Use CSS instead.
error: line 838: The tt element is obsolete. Use CSS instead.

$ w3c-validator http://www.methods.co.nz/asciidoc/layout1.css
validating: http://www.methods.co.nz/asciidoc/layout1.css ...

Resources

Prerequisites

Written and tested on Xubuntu 10.04 with Python 2.6.5, should work on other Python platforms.

« Previous Next »