change time and selector

This commit is contained in:
d4rtj 2022-09-01 18:47:09 +07:00
parent 34bb36211b
commit 59033df19b

View File

@ -4,7 +4,7 @@ const cheerio = require('cheerio');
const url = 'https://xosoketqua.com/xsmb-xo-so-mien-bac.html'; const url = 'https://xosoketqua.com/xsmb-xo-so-mien-bac.html';
class MainController { class MainController {
getAll = (req, res) => { getAll = async (req, res) => {
const numbers = []; const numbers = [];
const names = []; const names = [];
const times = []; const times = [];
@ -12,12 +12,12 @@ class MainController {
const obj = {}; const obj = {};
try { try {
axios(url).then(response => { await axios(url).then(response => {
const html = response.data; const html = response.data;
const $ = cheerio.load(html); // sử dụng giống jQuery const $ = cheerio.load(html); // sử dụng giống jQuery
$('table', html) $('table:nth-child(1)', html)
.first() // .first()
.each(function () { .each(function () {
$(this) $(this)
.find('td > span.div-horizontal') .find('td > span.div-horizontal')
@ -100,12 +100,19 @@ class MainController {
// }); // });
// } // }
const nowDay = new Date(); 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(nowDay.getHours() + ':' + nowDay.getMinutes());
// console.log(objTimesNames); // console.log(objTimesNames);
res.status(200).json({ res.status(200).json({
countNumbers: numbers.length, countNumbers: numbers.length,
time: nowDay, time: calendar,
objTimesNames, objTimesNames,
}); });
}); });