Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- ( async() =>
- {
- const request = require('request');
- const cheerio = require('cheerio');
- let categories = [];
- await new Promise( resolve =>
- {
- request('https://goldex.heureka.cz/kategorie/', async(err, resp, body) =>
- {
- let dom = cheerio.load(body);
- dom('div.brand-categories a').each( ( i, e ) => categories.push(e.attribs.href) );
- resolve();
- });
- });
- let products = {};
- for( let category of categories )
- {
- let offset = 0;
- console.log( category );
- while( true )
- {
- let productsCnt = await new Promise( resolve =>
- {
- request( category + '?f=' + offset, async(err, resp, body) =>
- {
- let dom = cheerio.load(body);
- let pruductURLs = [];
- dom('div.image a').each( ( i, e ) => pruductURLs.push(e.attribs.href) );
- console.log(pruductURLs)
- for( let productURL of pruductURLs )
- {
- await new Promise( resolve =>
- {
- request( productURL, async(err, resp, body) =>
- {
- let dom = cheerio.load(body);
- let categories =[];
- dom('span.js-gtm-breadcrumbs-item a').map(function(i, el) {
- categories.push(dom(this).text());
- })
- let prodnamimg = {};
- let name = dom('div.text-cover H1').text();
- let prices = dom('span.js-top-price').text();
- /* dom('a.sigProLink', 'div.itemImageGallery').each( ( i, e ) => images.push('http://www.orava.eu'+e.attribs.href));
- if( !images.length && dom('a.modal').length )
- {
- images.push('http://www.orava.eu'+ dom('a.modal').first()['0'].attribs.href );
- }
- */
- products[name] = { category: categories.join(' > '), price: prices };
- resolve( products );
- });
- });
- }
- resolve( pruductURLs.length );
- });
- });
- if( productsCnt < 60 ){ break; }
- offset += 1;
- }
- }
- require('fs').writeFileSync('export.json', JSON.stringify(products), function (err) {
- if (err) {
- return console.log(err);
- }
- console.log("The file was saved!");
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment