Google crawl issue with order of heirarchy in xml

#1

I want to crawl the google page , can any body help me to out put the desired value

start url : https://www.google.com/search?safe=off&q=list+of+private+clubs+in+london&npsic=0&rflfq=1&rlha=0&rllag=51514754,-104955,1876&tbm=lcl&ved=0ahUKEwjU67aV_tTaAhWJMY8KHYDQArgQjGoIYw&tbs=lrf:!2m1!1e2!2m1!1e3!3sIAE,lf:1,lf_ui:2&rldoc=1#rlfi=hd:;si:;mv:!1m3!1d13141.741038599976!2d-0.1280025!3d51.50443324999999!2m3!1f0!2f0!3f0!3m2!1i327!2i127!4f13.1;tbs:lrf:!2m1!1e2!2m1!1e3!3sIAE,lf:1,lf_ui:2

function pageFunction(context) {
// called on every page the crawler visits, use it to extract data from it
var = context.jQuery; console.log();

var clubs = []
var i,j;

var club_name = []; 
$('.dbg0pd').each(function(){
     club_name.push($(this).text().trim());
     //arrayObject.splice(i,0,{club_name:$(this).text().trim()});

     //i++;
});

var club_details = [];
   $('.rllt__details div span').each(function(){
     club_details.push($(this).text().trim());
   }); 

//what to do to combine

}

#2

I came up with this but it repeats the single data in one page why ??

var club_details = [];
$(’.cXedhc’).each((function(){

     var club_name = $('.dbg0pd').find('div').eq('0').text(); 
     var club_desc1 = $('.rllt__details').find('div').eq('0').text();
     var club_desc2 = $('.rllt__details').find('div').eq('1').text();
     var club_desc3 = $('.rllt__details').find('div').eq('2').text();
     var club_desc4 = $('.rllt__details').find('div').eq('3').text();
     var club_desc5 = $('.rllt__details').find('div').eq('4').text();

     var obj = {
         
         clubname:club_name,
         clubdesc1:club_desc1,
         clubdesc2:club_desc2,
         clubdesc3:club_desc3,
         clubdesc4:club_desc4,
         clubdesc5:club_desc5
         
     }
    club_details.push(obj);   
}));

return club_details;
#3

Hi @virtualqube,

You have to pick right elements during each. Now you take all of them:

Just update your code like this:

...
$(’.cXedhc’).each((function(){
         var club_name = $(this).find('.dbg0pd').eq('0').text(); 
         var club_desc1 = $(this).find('.rllt__details').find('div').eq('0').text();
         var club_desc2 = $(this).find('.rllt__details').find('div').eq('1').text();
         var club_desc3 = $(this).find('.rllt__details').find('div').eq('2').text();
         var club_desc4 = $(this).find('.rllt__details').find('div').eq('3').text();
         var club_desc5 = $(this).find('.rllt__details').find('div').eq('4').text();
...

Then it should work.

#4

Thanks it works , just missed the $this