Created
October 29, 2010 08:37
-
-
Save tjp/653154 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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