Last active
May 26, 2024 03:32
-
-
Save mynamebvh/a0e7f52fe726fd922d092d099ddc42d9 to your computer and use it in GitHub Desktop.
Thống kê học phí HaUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Tuition(time, status, money, note){ | |
this.time = time | |
this.moneyOrigin = money | |
this.status = status | |
this.money = money.toLocaleString('vi-VN', {style : 'currency', currency : 'VND'}) | |
this.note = note | |
} | |
function TuitionStatistic(year, total){ | |
this.year = year | |
this.totalOrigin = total | |
this.total = total.toLocaleString('vi-VN', {style : 'currency', currency : 'VND'}) | |
} | |
function parseHTMLToData(htmlString){ | |
const data = [] | |
const parser = new DOMParser(); | |
const document = parser.parseFromString(htmlString, 'text/html'); | |
const rows = document.querySelectorAll("#ctl02_ctl00_gvList tr") | |
for(let i = 1; i < rows.length; i++){ | |
const row = rows[i] | |
if(row.className == "Paging"){ | |
return data | |
} | |
const cells = row.querySelectorAll("td") | |
const status = cells[2].innerText.trim() | |
if(status != "-") continue | |
const time = cells[1].innerText.trim() | |
const money = parseInt(cells[3].innerText.replace(/\./g, '')) | |
const note = cells[4].innerText.trim() | |
data.push(new Tuition(time, status, money, note)) | |
} | |
return data | |
} | |
function getTransactionHistory(start_year, end_year){ | |
return fetch('https://sv.haui.edu.vn/student/recharge/transactionhistory', { | |
method: 'POST', | |
headers:{ | |
'Content-Type': 'application/x-www-form-urlencoded' | |
}, | |
body: new URLSearchParams({ | |
"__VIEWSTATEGENERATOR": document.getElementById("__VIEWSTATEGENERATOR").value, | |
"__VIEWSTATE": document.getElementById("__VIEWSTATE").value, | |
"klist": "0", | |
"klist2": "0", | |
"ctl02$ctl00$inpStartDate_d": "1", | |
"ctl02$ctl00$inpStartDate_m": "1", | |
"ctl02$ctl00$inpStartDate": start_year, | |
"ctl02$ctl00$inpEndDate_d": "1", | |
"ctl02$ctl00$inpEndDate_m": "1", | |
"ctl02$ctl00$inpEndDate": end_year, | |
"ctl02$ctl00$butGet": "Lọc dữ liệu" | |
}) | |
}); | |
} | |
function tuitionStatistics(start_year, data){ | |
const total = data.reduce((pre, tuition) => pre + tuition.moneyOrigin, 0) | |
return new TuitionStatistic(`${start_year} - ${start_year+1}`, total) | |
} | |
async function calculateTuition(){ | |
console.clear(); | |
console.log('%cĐang lấy dữ liệu lịch sử vui lòng đợi!!!', 'font-size: 30px; color: blue;'); | |
const tableTuition = [] | |
const tableStatictics = [] | |
let start_year = 2010 | |
while(start_year <= new Date().getFullYear()){ | |
const htmlString = await (await getTransactionHistory(start_year, start_year+1)).text() | |
const data = parseHTMLToData(htmlString) | |
if(data.length > 0){ | |
tableTuition.push(...data) | |
tableStatictics.push(tuitionStatistics(start_year, data)) | |
} | |
start_year++ | |
} | |
tableStatictics.push(new TuitionStatistic("All time", tableStatictics.reduce((pre, tuition) => pre + tuition.totalOrigin, 0))) | |
console.table(tableTuition, ["time", "status", "money", "note"]) | |
console.table(tableStatictics, ["year", "total"]) | |
} | |
calculateTuition().catch(err => console.error(err)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cách sử dụng:
Bước 1: Đăng nhập tài khoản sinh viên và chuyển hướng đến trang: https://sv.haui.edu.vn/student/recharge/transactionhistory
Bước 2: Mở F12 -> Qua tab console -> paste đoạn code trên vào ấn enter và chờ đợi