Node.js noob. I am using node.io to scrape websites but I would love to use jquery within node.io. The $ object provided by node.io doesn’t provide much flexibility.
var nodeio = require('node.io'), options = {timeout: 10},
jQuery = require('jquery');
exports.job = new nodeio.Job(options, {
input: ['hello', 'foobar', 'weather'],
run: function (keyword) {
this.getHtml('http://www.google.com/search?q=' + encodeURIComponent(keyword), function (err, $) {
// SOMEHOW CREATE THE JQUERY OBJECT USING $
var results = $('#resultStats').text.toLowerCase();
this.emit(keyword + ' has ' + results);
});
}
});
Can anyone help?
UPDATE
I din’t notice that node.io had an option to use jquery with the jsdom:true option. It doesn’t work even when I use this option, I always get a timeout error OR $ is undefined error.
Ok, figured out the problem.
node.io has an option to use jquery, you need to pass this option
jsdom:true. The version of node.io (0.3.0) I was using had a bug in it which always returned a timeout.Now this is fixed in node.io version 0.3.1
Thank you all for your response!