【问题标题】:Node.js scraiping using Node.ioNode.js 使用 Node.io 抓取
【发布时间】:2011-07-14 13:42:42
【问题描述】:

我正在尝试 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);

但结果我什么也没得到。怎么了?

谢谢

【问题讨论】:

    标签: node.js web-scraping


    【解决方案1】:

    您没有准确地遍历标记。而且您对each 的使用不正确。试试这个:

    $('a', '.content h3').each(function(index, a) {console.log($(a).text())});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-02
      • 1970-01-01
      • 2015-08-09
      • 2017-06-23
      • 2011-07-09
      • 1970-01-01
      相关资源
      最近更新 更多