Skip to content

Instantly share code, notes, and snippets.

@tjp
Created October 29, 2010 08:37
Show Gist options
  • Save tjp/653154 to your computer and use it in GitHub Desktop.
Save tjp/653154 to your computer and use it in GitHub Desktop.
//http://blog.nodejitsu.com/jsdom-jquery-in-5-lines-on-nodejs
var httpAgent = require('http-agent'),
jsdom = require('jsdom'),
sys = require('sys');
var agent = httpAgent.create('www.google.com', ['finance', 'news', 'images']);
//original line:
//agent.addListener('next', function (agent) {
//this breaks because the callback comes back with different arguments.
//this fixes it
agent.addListener('next', function (e,agent) {
var window = jsdom.jsdom(agent.body).createWindow();
jsdom.jQueryify(window, 'jquery.js', function (window, jquery) {
// jQuery is now loaded on the jsdom window created from 'agent.body'
//jQuery('.someClass').each(function () { /* Your custom logic */ });
agent.next();
});
});
agent.addListener('stop', function (agent) {
sys.puts('the agent has stopped');
});
agent.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment