PhantomJS gives you command-line access to the features of WebKit. According to its website: "Literally it acts like any other WebKit-based web browser, except that nothing gets displayed to the screen (thus, the term headless)." It has native support for DOM handling, CSS selector, JSON, Canvas, SVG, and JavaScript.