Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require("http");
- var {linkType, get} = require("get-content");
- var cheerio = require("cheerio");
- http.createServer(function (req, res) {
- var url = "https://www.lazada.co.id/";
- get(url).then((pageContent) => {
- $ = cheerio.load(pageContent);
- var result = new Array();
- // var target = $('.c-slider__row','.c-slider__wrapper','.c-slider' ,'.c-mp-section__body','.c-layout-container__section' ,'.c-recommendation__content').find(".c-slider__slide");
- var target = $('.c-recommendation__content').find(".c-slider__slide");
- $(target).each(function(i, elem) {
- temp1 = $('a' ,$(this).html()).html();
- img = $('.c-img-lazy' ,temp1).attr("data-js-component-params");
- img = img.split('src\": \"')[1];
- img = img.split('\"\n')[0];
- result.push({'img':img, 'link':$('a' ,$(this).html()).attr("href"), 'title':$('.c-product-item__title' ,temp1).text().trim(), 'price_new':$('.c-product-item__price' ,temp1).text().replace(/\n/g, "").trim(), 'price_old':$('.c-product-item__price-old' ,temp1).text().trim(), 'discount':$('.c-product-item__discount' ,temp1).text().trim()});
- });
- res.writeHeader(200, {"Content-Type": "text/html"});
- res.write(JSON.stringify(result));
- res.end();
- }).catch((err) => {console.warn(err);});
- }).listen(8081);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement