const http = require('http'); const cheerio = require('cheerio'); http.get( 'http://thuoctot24h.com/thuc-pham-chuc-nang/sinh-lysinh-san-nu', function(res) { let rawData = ''; res.on('data', (chunk) => { rawData += chunk; }); res.on('end', async() => { const $ = await cheerio.load(rawData); const selecTenSP = $('div.list-item'); var listURL = []; for (var i = 0; i < selecTenSP.length; i++) { listURL.push(selecTenSP[i].children[0].children[0].children[1].attribs.href); } 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); var data = []; //ten thuoc const selecTenSP = $('h1.title-name-product'); var tenSP = selecTenSP[0].children[0].data; data.push(tenSP); //Gia const selecGiaSP = $('span.lb-price.price-main'); var giaSP = selecGiaSP[0].children[0].data; data.push(giaSP); var selec = $('#content > h2'); var listCongDung = []; for (var i = 0; i < selec.length; i++) { var line = []; line.push(selec[i].children[0].data); while (selec[i].next.name == 'p') { if (selec[i].next.children[0].data != null) line.push(selec[i].next.children[0].data); selec[i] = selec[i].next; if (selec[i].next == null) break; } data.push(line); } console.log(data); }) } ) }) }) } )