First you need a JavaScript runtime environment outside the browser. The most common is Node.js. Then you need a way to create the client part of the DOM. This is usually done using jsdom .
So your script should:
- load the html page (
jsdom does this for you, but you can use request ) - create a client-side DOM
- jQuery analysis
Here is an example Node.js script:
var jsdom = require("jsdom"); jsdom.env("http://nodejs.org/dist/", [ 'http://code.jquery.com/jquery-1.5.min.js' ], function(errors, window) { console.log("there have been", window.$("a").length, "nodejs releases!"); });
You run it like this:
$ node scrape.js
Remember to install jsdom first:
$ npm install
source share