Node.js scraiping using Node.io
I am trying Node.js to get all the titles of this page: https://www.odesk.com/jobs/braintree
I try this:
var nodeio = require('node.io');
var methods = {
input: false,
run: function() {
this.getHtml('https://www.odesk.com/jobs/braintree/', function(err, $) {
//Handle any request / parsing errors
if (err) this.exit(err);
var titles = [], scores = [], output = [];
//Select all titles on the page
$('.content').each(function(a) {
titles.push(a.text);
});
this.emit(output开发者_如何学Go);
});
}
}
exports.job = new nodeio.Job({timeout:10}, methods);
But I'm getting nothing as a result. What is wrong?
Thanks
You aren't accurately traversing the markup. And your use of each
is incorrect. Try this:
$('a', '.content h3').each(function(index, a) {console.log($(a).text())});
精彩评论