const http = require('https'); const cheerio = require('cheerio'); http.get( 'https://www.muathuoc.vn/tim-mach', function(res) { let rawData = ''; res.on('data', (chunk) => { rawData += chunk; }); res.on('end', async() => { const $ = await cheerio.load(rawData); var listURL = []; let listData = []; var rootURL = 'https://www.muathuoc.vn'; const selecTenSP = $('#grid_pagination > div.grid > div:nth-child(1) > div:nth-child(1) > div > div.product-image > div'); const list = $('div.product_overlay.style_1'); for (var i = 0; i < list.length; i++) { listURL.push(rootURL + list[i].attribs.product_url); } listURL.forEach(function(motPhanTu) { http.get( motPhanTu, function(res) { let rawData = ''; res.on('data', (chunk) => { rawData += chunk; }); res.on('end', async() => { const $ = await cheerio.load(rawData); //Tên thuốc const selecTenSP = $('#ProductDetailsForm > div > div > div.col-md-6.norightpadding.pd_desc_wrapper > div > div.page_title > h2'); var tenSP = [] tenSP = selecTenSP[0].children[0].data; const selecDGSP = $('#tabs-1 > p'); var data = []; data.push(tenSP); try { for (var i = 0; i < selecDGSP.length; i++) { selecDGSP[i].children[0].children.forEach(function(motPhanTu) { if (motPhanTu.data != null) data.push(motPhanTu.data); }); } } catch (error) { } console.log(data); }) } ) }); }) } );