0

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

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;
}
4

1 回答 1

0

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

家长(推荐人)请求可通过context.referrer. 如果你改变它,你可以重新入队uniqueKey

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

于 2018-05-17T10:09:55.530 回答