【问题标题】:Need APIFY crawling data需要APIFY爬取数据
【发布时间】:2018-05-15 18:50:37
【问题描述】:

我只想获取通过爬行获得的生产细节。我想去下一页然后回来。我该怎么做,因为可用的参考资料不多?

function pageFunction(context) {
    // called on every page the crawler visits, use it to extract data from it
    var $ = context.jQuery;
    var results = [];
        context.willFinishLater()
        setTimeout(function(){
            context.saveSnapshot()
            var  U = "";
            if(context.request.label==='START'){
                 $(".wyr8u9C38ajt_81OEEJS0").each(function(){
                    u = window.location.origin + $(this).find('a').attr('href');
                    results.push({
                        //productname: $(this).find('._2zb0403rv6_TmGr5AuQdDL _3ZymdXsJIpZFSdoFz7SXGz _2FhmkzjV0mn3CQVnLDbZX7').attr(src)
                         productname : $(this).find('._10yEIgoNxRH2oiIFjtZAOU').text(),
                         productimage : $(this).find('[property="image"]').css('background-image').replace('url(','').replace(')',''),
                         productcurrency: $(this).find('meta[property="priceCurrency"]').attr('content'),
                         productprice :$(this).find('._2Ke7gNjoZGfGt6jafzQDFK span:nth-child(2)').text(),
                         productrating :$(this).find('._3y-Pd4U1hs-et3GKdZ-Fe- span').text(),
                         producturl: window.location.origin + $(this).find('a').attr('href')

                       //  productdesc : $(this).next('._2ZGju-MCzPFgpryXbE_mgT').html()
                    });
                   // U = window.location.origin + $(this).find('a').attr('href');
                    enqueuePage((window.location.origin + $(this).find('a').attr('href')))
            }); 
            //context.skipOutput();
            }else if(context.request.label==='productlabel'){
                results.push({
                    peter : "43"
                });
            }

            //context.skipOutput();
            //va = context.enqueuePage() 
            context.finish(results);
        },10000);
    return results;
}

【问题讨论】:

    标签: api web-crawler domcrawler apify


    【解决方案1】:

    您的用例到底是什么?您需要将数据从子页面传递给父页面吗?

    可通过context.referrer 获得父(推荐人)请求。如果你改变它的uniqueKey,你可以重新入队。

    也可以通过context.referrer. pageFunctionResult获得来自推荐人的页面功能结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      • 1970-01-01
      相关资源
      最近更新 更多