Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. var categorieTag = '.osh-cat-header .title'
  2. var siteTag = '.logo a img'
  3. var productEnvelopeTag = '.sku'
  4. var imageLinkTag = '.image-wrapper img '
  5. var productNameTag = '.name'
  6. var priceTag = '.price'
  7. var currencyTag = '.data-currency-iso'
  8. var availabilityTag = '#stock_availability'
  9. var productRefTag = '.product-reference'
  10. var productLink = '.product-title a'
  11.  
  12. function getHtmlSite(){
  13. return (fetch(`${link}`).then(response => response.text()))
  14. }
  15. getHtmlSite()
  16. .then(body => {
  17.  
  18. const $ = cheerio.load(body);
  19. var $categorie= $(categorieTag).children().remove().end().text();
  20. var $site= $(siteTag);
  21. $(productEnvelopeTag).each(function(i,element) {
  22. const $image = $(element).find(imageLinkTag);
  23. const $productName = $(element).find(productNameTag);
  24. const $price = $(element).find(priceTag);
  25. const $currencyTag = $(element).find(currencyTag);
  26. const $availability = $(element).find(availabilityTag)
  27. const $refProduct = $(element).find(productRefTag);
  28. const $productLink = $(element).find(productLink);
  29. product = {
  30. image : $image.attr('src'),
  31. productName : $productName.text(),
  32. price : $price.text().trim(),
  33. currencyTag : $currencyTag.text().trim(),
  34. categorie : $categorie,
  35. availability : $availability.text().trim(),
  36. site : $site.attr('alt'),
  37. refProduct : $refProduct.text(),
  38. prodcutLink : $productLink.attr('href')
  39. }
  40.  
  41. allProducts.push(product);
  42. })
  43.  
  44. fs.writeFileSync('JumiaProducts.json',JSON.stringify(allProducts, null , 2));
  45. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement