const http = require('https'); const cheerio = require('cheerio'); http.get( 'https://quaythuoc.org/gastrogel-ho-tro-benh-da-day-hieu-qua.html', function(res) { let rawData = ''; res.on('data', (chunk) => { rawData += chunk; }); res.on('end', async() => { const $ = await cheerio.load(rawData); //Tên thuốc const nameProduct = $('body > section > div.rowdetail > aside.price_sale > div:nth-child(1) > h1'); var name = nameProduct[0].children[0].data; const selector = $('body > section > div.box_content > aside.left_content.productDetailContent > div.content.showAll > div.content_post_vie > ul'); const listThanhPhan = []; const listCongDung = []; const listCachDung = []; const listChongChiDinh = []; const ListNhasx = []; for (var j = 0; j < selector.length; j++) { switch (j) { case 0: { for (var i = 0; i < selector[j].children.length; i++) { listThanhPhan.push(selector[j].children[i].children[0].data); } break; } case 1: { for (var i = 0; i < selector[j].children.length; i++) { listCongDung.push(selector[j].children[i].children[0].data); } break; } case 2: { for (var i = 0; i < selector[j].children.length; i++) { listCachDung.push(selector[j].children[i].children[0].data); } break; } case 4: { for (var i = 0; i < selector[j].children.length; i++) { listChongChiDinh.push(selector[j].children[i].children[0].data); } break; } case 6: { for (var i = 0; i < selector[j].children.length; i++) { ListNhasx.push(selector[j].children[i].children[0].data); } break; } default: continue; } } var data = { ten: name, thanhPhan: listThanhPhan, congDung: listCongDung, cachDung: listCachDung, chongChiDinh: listChongChiDinh, nhaSX: ListNhasx }; const str = JSON.stringify(data); console.log(str); }) } )