From 59033df19b977e9a8b2a7df393eb073c72948593 Mon Sep 17 00:00:00 2001 From: d4rtj Date: Thu, 1 Sep 2022 18:47:09 +0700 Subject: [PATCH] change time and selector --- controllers/mainController.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/controllers/mainController.js b/controllers/mainController.js index 3e047d2..39acd0d 100644 --- a/controllers/mainController.js +++ b/controllers/mainController.js @@ -4,7 +4,7 @@ const cheerio = require('cheerio'); const url = 'https://xosoketqua.com/xsmb-xo-so-mien-bac.html'; class MainController { - getAll = (req, res) => { + getAll = async (req, res) => { const numbers = []; const names = []; const times = []; @@ -12,12 +12,12 @@ class MainController { const obj = {}; try { - axios(url).then(response => { + await axios(url).then(response => { const html = response.data; const $ = cheerio.load(html); // sử dụng giống jQuery - $('table', html) - .first() + $('table:nth-child(1)', html) + // .first() .each(function () { $(this) .find('td > span.div-horizontal') @@ -100,12 +100,19 @@ class MainController { // }); // } const nowDay = new Date(); - // console.log(nowDay.getDate() + '/' + ((nowDay.getMonth() + 1) < 10 ? ('0'+ (nowDay.getMonth() + 1)) : (nowDay.getMonth() + 1)) + '/' + nowDay.getFullYear()); + const calendar = + nowDay.getDate() + + '/' + + (nowDay.getMonth() + 1 < 10 + ? '0' + (nowDay.getMonth() + 1) + : nowDay.getMonth() + 1) + + '/' + + nowDay.getFullYear(); // console.log(nowDay.getHours() + ':' + nowDay.getMinutes()); // console.log(objTimesNames); res.status(200).json({ countNumbers: numbers.length, - time: nowDay, + time: calendar, objTimesNames, }); });