const http = require('http'); const cheerio = require('cheerio'); http.get( 'http://thuoctot24h.com/sam-to-nu-puecolazen-tra-lai-tuoi-xuan.html', 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); }) } )