Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const request = require('request');
  2. const cheerio = require('cheerio');
  3.  
  4. var url = 'https://www.coolshop.de/sitemap.xml';
  5.  
  6.  
  7. //First loop
  8. request(url,
  9. (error, response, html) => {
  10.   if(!error && response.statusCode == 200) {
  11.     var array = [];
  12.     const $ = cheerio.load(html, {xmlMode: true});
  13.  
  14.     links = $('loc');
  15.     $(links).each(function(i, link) {
  16.     //  var loc = $(link).attr('loc');
  17.       //array.push(loc);
  18.  
  19.     //  console.log($(link).text());
  20.  
  21.       var jrl = ($(link).text());
  22. //Second loop
  23.       request(jrl,
  24.       (error, response, html) => {
  25.         if(!error && response.statusCode == 200) {
  26.           const $ = cheerio.load(html, {xmlMode: true});
  27.           linx = $('loc');
  28.           $(linx).each(function(i, link) {
  29.         //    console.log($(link).text());
  30.  
  31.  
  32.             var hrl = ($(link).text());
  33. //Third loop
  34.             request(hrl,
  35.             (error, response,html) => {
  36.               if(!error && response.statusCode == 200) {
  37.                 const $ = cheerio.load(html);
  38.  
  39.                 const id = $('#attributeSku');
  40.  
  41.                 const name = $('.thing-header');
  42.  
  43.                 const description = $('.thing.descriptions');
  44.                
  45.                 //Ovo je deo koji ne radi
  46.                 const photo = $('.thing-cover__image gallery-item').attr('href');
  47.  
  48.                 const firstPrice = $('.thing-buy-box-price price-with-decimal-large price');
  49.  
  50.                 const secondPrice = $('.after-decimal');
  51.  
  52.                 const output = photo;
  53.                 //Ovde sam svasta probao
  54.                 console.log(($(photo).text());
  55.  
  56.               }
  57.             });
  58.           });
  59.         }
  60.       });
  61.     });
  62.     }
  63. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement