Compare commits

..

10 Commits

Author SHA1 Message Date
Đạt
9b3f459e2a
Update link 2024-04-30 15:31:14 +07:00
ttD4T
26bcb8f30f Update README 2023-06-19 10:00:37 +07:00
ttD4T
02d96ddf88 Config url & update README 2023-06-19 09:53:59 +07:00
ttD4T
278023bcd2 Update realtime 2023-06-14 18:23:07 +07:00
ttD4T
a9fda0d509 Change api link 2023-06-14 00:17:59 +07:00
ttD4T
ba6fac22fb Change title results 2023-06-13 22:29:03 +07:00
ttD4T
6040461666 Change url web-scraped 2023-06-13 22:23:57 +07:00
DDatj
aa2da5ecbd update host 2022-11-15 11:29:38 +07:00
d4rtj
9dfc86a044 update array 2022-10-28 22:15:01 +07:00
d4rtj
69715516d6 change names 2022-10-28 12:11:00 +07:00
6 changed files with 140 additions and 116 deletions

2
.env Normal file
View File

@ -0,0 +1,2 @@
URL=https://az24.vn/xsmb-sxmb-xo-so-mien-bac.html
#https://xosoketqua.com/xsmb-xo-so-mien-bac.html[DA TUNG SU DUNG]

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/node_modules /node_modules
package-lock.json package-lock.json
.env

View File

@ -1,19 +1,17 @@
# api-xsmb-today # api-xsmb-today
> take infor from api by https://api-xsmb-today.herokuapp.com/v1 > take info from api by [https://api-xsmb.cyclic.app/api/v1](https://api-xsmb-today.onrender.com/api/v1)
>
> web-scraped from https://xosoketqua.com/xsmb-xo-so-mien-bac.html
--- ---
| Keys | Type | | Keys | Type |
| ---- | ------ | | ---- | ------------ |
| time | String | | time | Array String |
| G.ĐB | String | | ĐB | Array String |
| G.1 | String | | G1 | Array String |
| G.2 | String | | G2 | Array String |
| G.3 | String | | G3 | Array String |
| G.4 | String | | G4 | Array String |
| G.5 | String | | G5 | Array String |
| G.6 | String | | G6 | Array String |
| G.7 | String | | G7 | Array String |

View File

@ -1,124 +1,147 @@
const axios = require('axios'); const axios = require('axios');
const cheerio = require('cheerio'); const cheerio = require('cheerio');
require('dotenv').config();
const url = 'https://xosoketqua.com/xsmb-xo-so-mien-bac.html';
const url = process.env.URL;
class MainController { class MainController {
getAll = async (req, res) => { getAll = async (req, res) => {
const numbers = []; const numbers = [];
const names = []; const names = [];
const times = []; const results = {};
const objTimesNames = {};
const obj = {};
try { try {
await axios(url).then(response => { axios(url, {
const html = response.data; method: 'GET',
const $ = cheerio.load(html); // sử dụng giống jQuery })
.then((response) => {
const html = response.data;
const $ = cheerio.load(html); // sử dụng giống jQuery
$('table:nth-child(1)', html) $('table:nth-child(1)', html)
// .first() .first()
.each(function () { .each(function () {
$(this) $(this)
.find('td > span.div-horizontal') .find('td.v-giai > span ')
.each(function () { .each(function () {
numbers.push($(this).text()); numbers.push($(this).text());
}); });
// console.log(numbers); $(this)
$(this) .find('tr > td:first-child')
.find('tr > td:first-child') .each(function (i) {
.each(function (i) { const name = $(this).text();
const name = $(this).text();
if (name !== 'Mã ĐB') { if (!name.includes('Mã ĐB')) {
// for (let i = 0; i < names.length; i++) { // for (let i = 0; i < names.length; i++) {
if (names.includes(name)) { if (names.includes(name)) {
return; return;
} else { } else {
names.push(name); names.push(
name
.replace('Giải', 'G')
.split(' ')
.join('')
);
}
// }
} }
// } });
} });
}); numbers.splice(0, 1); // xóa phần tử đầu tiên
}); if (numbers.length > 0) {
if (numbers.length > 0) { for (let i = 0; i < names.length; i++) {
for (let i = 0; i < names.length; i++) { results[names[0]] = [
objTimesNames[names[0]] = numbers[0]; numbers[0] ? numbers[0] : 'Đang cập nhật',
objTimesNames[names[1]] = numbers[1]; ];
objTimesNames[names[2]] = [numbers[2], numbers[3]]; results[names[1]] = [
objTimesNames[names[3]] = [ numbers[1] ? numbers[1] : 'Đang cập nhật',
numbers[4], ];
numbers[5], results[names[2]] = [
numbers[6], numbers[2] ? numbers[2] : 'Đang cập nhật',
numbers[7], numbers[3] ? numbers[3] : 'Đang cập nhật',
numbers[8], ];
numbers[9], results[names[3]] = [
]; numbers[4] ? numbers[4] : 'Đang cập nhật',
objTimesNames[names[4]] = [ numbers[5] ? numbers[5] : 'Đang cập nhật',
numbers[10], numbers[6] ? numbers[6] : 'Đang cập nhật',
numbers[11], numbers[7] ? numbers[7] : 'Đang cập nhật',
numbers[12], numbers[8] ? numbers[8] : 'Đang cập nhật',
numbers[13], numbers[9] ? numbers[9] : 'Đang cập nhật',
]; ];
objTimesNames[names[5]] = [ results[names[4]] = [
numbers[14], numbers[10] ? numbers[10] : 'Đang cập nhật',
numbers[15], numbers[11] ? numbers[11] : 'Đang cập nhật',
numbers[16], numbers[12] ? numbers[12] : 'Đang cập nhật',
numbers[17], numbers[13] ? numbers[13] : 'Đang cập nhật',
numbers[18], ];
numbers[19], results[names[5]] = [
]; numbers[14] ? numbers[14] : 'Đang cập nhật',
objTimesNames[names[6]] = [ numbers[15] ? numbers[15] : 'Đang cập nhật',
numbers[20], numbers[16] ? numbers[16] : 'Đang cập nhật',
numbers[21], numbers[17] ? numbers[17] : 'Đang cập nhật',
numbers[22], numbers[18] ? numbers[18] : 'Đang cập nhật',
]; numbers[19] ? numbers[19] : 'Đang cập nhật',
objTimesNames[names[7]] = [ ];
numbers[23], results[names[6]] = [
numbers[24], numbers[20] ? numbers[20] : 'Đang cập nhật',
numbers[25], numbers[21] ? numbers[21] : 'Đang cập nhật',
numbers[26], numbers[22] ? numbers[22] : 'Đang cập nhật',
]; ];
results[names[7]] = [
numbers[23] ? numbers[23] : 'Đang cập nhật',
numbers[24] ? numbers[24] : 'Đang cập nhật',
numbers[25] ? numbers[25] : 'Đang cập nhật',
numbers[26] ? numbers[26] : 'Đang cập nhật',
];
}
} }
}
// $('.list-link', html) // $('.list-link', html)
// .find('h2 > a:last-child') // .find('h2 > a:last-child')
// .each(function () { // .each(function () {
// const time = $(this).prop('innerHTML').split(' ')[1]; // const time = $(this).prop('innerHTML').split(' ')[1];
// // times.push(time); // times.push(time);
// console.log(time); // console.log(time);
// }); // });
// if (times.length > 0) { // if (times.length > 0) {
// times.forEach(time => { // times.forEach(time => {
// for (let i = 0; i < names.length; i++) { // for (let i = 0; i < names.length; i++) {
// objTimesNames[time] = [...names]; // results[time] = [...names];
// } // }
// }); // });
// } // }
const nowDay = new Date(); const nowDay = new Date();
const calendar = const calendar =
nowDay.getDate() + nowDay.getDate() +
'/' + '/' +
(nowDay.getMonth() + 1 < 10 (nowDay.getMonth() + 1 < 10
? '0' + (nowDay.getMonth() + 1) ? '0' + (nowDay.getMonth() + 1)
: nowDay.getMonth() + 1) + : nowDay.getMonth() + 1) +
'/' + '/' +
nowDay.getFullYear(); nowDay.getFullYear();
// console.log(nowDay.getHours() + ':' + nowDay.getMinutes()); // console.log(nowDay.getHours() + ':' + nowDay.getMinutes());
// console.log(objTimesNames); // console.log(results);
const date = $('.class-title-list-link', html).first().find('a:last-child').text().split(' ')[1]; const date = $('div.tit-mien.clearfix.txt-center > div', html)
.first()
.find('a:last-child')
.text()
.split(' ')[2];
res.status(200).json({ res.status(200).json({
countNumbers: numbers.length, countNumbers: numbers.length,
time: date, time: date,
objTimesNames, results,
});
})
.catch((err) => {
console.log(err);
return res.status(500).json({ msg: err });
}); });
});
} catch (e) { } catch (e) {
res.status(500).json({ msg: e }); res.status(500).json({ msg: e });
} }

View File

@ -2,7 +2,7 @@
"name": "apixsmb", "name": "apixsmb",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.js", "main": "app.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js", "start": "node app.js",

View File

@ -1,7 +1,7 @@
const routeV1 = require('./v1/index'); const routeV1 = require('./v1/index');
const routes = app => { const routes = app => {
app.use('/v1', routeV1); app.use('/api/v1', routeV1);
}; };
module.exports = routes; module.exports = routes;