我正在尝试Node.js获取此页面的所有标题:https://www.odesk.com/jobs/braintree
我试试这个:
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);
});
}
}
exports.job = new nodeio.Job({timeout:10}, methods);
但结果却没有得到任何结果。有什么问题?
由于
答案 0 :(得分:1)
您没有准确地遍历标记。您对each
的使用不正确。试试这个:
$('a', '.content h3').each(function(index, a) {console.log($(a).text())});