【问题标题】:Scraping multiple pages with Phantomjs/Pjscrape使用 Phantomjs/Pjscrape 抓取多个页面
【发布时间】:2012-11-27 10:43:24
【问题描述】:

试图抓取多个页面,但无法让 urlid 数组在 pjscrape .js 文件中工作。

我很确定我可能会犯一个新手错误,但我希望能得到一些帮助。 谢谢:)

pjs.config({

    timeoutInterval: 6000,
    timeoutLimit: 10000,

})

pjs.addSuite({
    // single URL or array
    url: abolaURLs,
    scraper: function(){
        var abolaURLs = [366762,366764,366763];
        for (var i = 0; i<abolaURLs.length; i++) {
            abolaURLs[i] = 'http://abola.pt/nnh/ver.aspx?id=' + abolaURLs[i];
        };
        var results[];
        var cenas1 = $('div#a5g2').text();
        var cenas2 = $('span#noticiatext').text();
        var cenas3 = $('div#a5x').text();
        results.push(cenas1, cenas2, cenas3);
        return results;
    }
});

【问题讨论】:

    标签: javascript screen-scraping web-scraping phantomjs


    【解决方案1】:

    这对你有用:

    var abolaURLs = [366762,366764,366763];
    
    for (var i = 0; i < abolaURLs.length; i++) {
        abolaURLs[i] = 'http://abola.pt/nnh/ver.aspx?id=' + abolaURLs[i];
    };
    
    pjs.addSuite({
        url: abolaURLs,
        scraper: function() {
                var results = []; // !! you have the wrong array declaration result[]
                var cenas1 = $('div#a5g2').text();
                var cenas2 = $('span#noticiatext').text();
                var cenas3 = $('div#a5x').text();
                results.push(cenas1, cenas2, cenas3);
                return results;
        }
    });
    
    pjs.config({
        timeoutInterval: 6000,
        timeoutLimit: 10000,
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多