Compare commits
10 Commits
046741181b
...
9b3f459e2a
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9b3f459e2a | ||
![]() |
26bcb8f30f | ||
![]() |
02d96ddf88 | ||
![]() |
278023bcd2 | ||
![]() |
a9fda0d509 | ||
![]() |
ba6fac22fb | ||
![]() |
6040461666 | ||
![]() |
aa2da5ecbd | ||
![]() |
9dfc86a044 | ||
![]() |
69715516d6 |
2
.env
Normal file
2
.env
Normal 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
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
/node_modules
|
/node_modules
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
.env
|
||||||
|
24
README.md
24
README.md
@ -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 |
|
||||||
|
@ -1,84 +1,99 @@
|
|||||||
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, {
|
||||||
|
method: 'GET',
|
||||||
|
})
|
||||||
|
.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: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++) {
|
||||||
objTimesNames[names[0]] = numbers[0];
|
results[names[0]] = [
|
||||||
objTimesNames[names[1]] = numbers[1];
|
numbers[0] ? numbers[0] : 'Đang cập nhật',
|
||||||
objTimesNames[names[2]] = [numbers[2], numbers[3]];
|
|
||||||
objTimesNames[names[3]] = [
|
|
||||||
numbers[4],
|
|
||||||
numbers[5],
|
|
||||||
numbers[6],
|
|
||||||
numbers[7],
|
|
||||||
numbers[8],
|
|
||||||
numbers[9],
|
|
||||||
];
|
];
|
||||||
objTimesNames[names[4]] = [
|
results[names[1]] = [
|
||||||
numbers[10],
|
numbers[1] ? numbers[1] : 'Đang cập nhật',
|
||||||
numbers[11],
|
|
||||||
numbers[12],
|
|
||||||
numbers[13],
|
|
||||||
];
|
];
|
||||||
objTimesNames[names[5]] = [
|
results[names[2]] = [
|
||||||
numbers[14],
|
numbers[2] ? numbers[2] : 'Đang cập nhật',
|
||||||
numbers[15],
|
numbers[3] ? numbers[3] : 'Đang cập nhật',
|
||||||
numbers[16],
|
|
||||||
numbers[17],
|
|
||||||
numbers[18],
|
|
||||||
numbers[19],
|
|
||||||
];
|
];
|
||||||
objTimesNames[names[6]] = [
|
results[names[3]] = [
|
||||||
numbers[20],
|
numbers[4] ? numbers[4] : 'Đang cập nhật',
|
||||||
numbers[21],
|
numbers[5] ? numbers[5] : 'Đang cập nhật',
|
||||||
numbers[22],
|
numbers[6] ? numbers[6] : 'Đang cập nhật',
|
||||||
|
numbers[7] ? numbers[7] : 'Đang cập nhật',
|
||||||
|
numbers[8] ? numbers[8] : 'Đang cập nhật',
|
||||||
|
numbers[9] ? numbers[9] : 'Đang cập nhật',
|
||||||
];
|
];
|
||||||
objTimesNames[names[7]] = [
|
results[names[4]] = [
|
||||||
numbers[23],
|
numbers[10] ? numbers[10] : 'Đang cập nhật',
|
||||||
numbers[24],
|
numbers[11] ? numbers[11] : 'Đang cập nhật',
|
||||||
numbers[25],
|
numbers[12] ? numbers[12] : 'Đang cập nhật',
|
||||||
numbers[26],
|
numbers[13] ? numbers[13] : 'Đang cập nhật',
|
||||||
|
];
|
||||||
|
results[names[5]] = [
|
||||||
|
numbers[14] ? numbers[14] : 'Đang cập nhật',
|
||||||
|
numbers[15] ? numbers[15] : 'Đang cập nhật',
|
||||||
|
numbers[16] ? numbers[16] : 'Đang cập nhật',
|
||||||
|
numbers[17] ? numbers[17] : 'Đang cập nhật',
|
||||||
|
numbers[18] ? numbers[18] : 'Đang cập nhật',
|
||||||
|
numbers[19] ? numbers[19] : 'Đang cập nhật',
|
||||||
|
];
|
||||||
|
results[names[6]] = [
|
||||||
|
numbers[20] ? numbers[20] : 'Đang cập nhật',
|
||||||
|
numbers[21] ? numbers[21] : 'Đang cập nhật',
|
||||||
|
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',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,14 +103,14 @@ class MainController {
|
|||||||
// .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];
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
@ -109,15 +124,23 @@ class MainController {
|
|||||||
'/' +
|
'/' +
|
||||||
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 });
|
||||||
|
@ -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",
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user