开发者

Node.js scraiping using Node.io

开发者 https://www.devze.com 2023-03-20 02:45 出处:网络
I am trying Node.js to get all the titles of this page: https://www.odesk.com/jobs/braintree I try this:

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())});
0

精彩评论

暂无评论...
验证码 换一张
取 消