forked from thanhpv3380/auto-grade-ouput-hust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
93 lines (79 loc) · 2.66 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { Builder, By, Key } from "selenium-webdriver";
import dotenv from "dotenv";
dotenv.config();
// EMAIL: là mã số sinh viên
// PASSWORD: là mật khẩu
// 1. TIMETABLE: xem thời khóa biểu
// 2. GRADE_TERM: xem điểm kì mới nhất
// 3. COURSE_MARKS: xem bảng điểm cá nhân
// 4. COURSE_GRADE: xem bảng điểm học phần
// 5. TUITION: xem học phí
async function init({ email, password }) {
let courseMarks = [];
let driver = await new Builder().forBrowser("MicrosoftEdge").build();
try {
await driver.get("https://ctt-sis.hust.edu.vn/Account/Login.aspx");
// type email/mssv
await driver
.findElement(
By.id("ctl00_ctl00_contentPane_MainPanel_MainContent_tbUserName_I")
)
.sendKeys(email, Key.TAB, password);
// wait 8s to type captcha
await driver.sleep(5000);
// click login
await driver
.findElement(
By.id("ctl00_ctl00_contentPane_MainPanel_MainContent_btLogin")
)
.click();
// access course marks
await driver.get(
"https://ctt-sis.hust.edu.vn/Students/StudentCourseMarks.aspx"
);
// wait 1s to change redirect
await driver.sleep(5000);
// get header title
const headerTableGrade = await driver.findElement(
By.id(
"ctl00_ctl00_contentPane_MainPanel_MainContent_gvCourseMarks_DXHeadersRow0"
)
);
const headerColsEle = await headerTableGrade.findElements(
By.className("dxgvHeader")
);
let headerData = [];
for (let i = 0; i < headerColsEle.length - 1; i++) {
const cols = await headerColsEle[i].findElements(
By.css("table tbody tr td")
);
const text = await cols[0].getText();
headerData.push(text);
}
// get content
const tableGrade = await driver.findElement(
By.id(
"ctl00_ctl00_contentPane_MainPanel_MainContent_gvCourseMarks_DXMainTable"
)
);
await driver.sleep(1000);
const rowsEle = await tableGrade.findElements(By.className("dxgvDataRow"));
const rowTemplate =
"ctl00_ctl00_contentPane_MainPanel_MainContent_gvCourseMarks_DXDataRow";
for (let i = 0; i < rowsEle.length; i++) {
const row = await tableGrade.findElement(By.id(`${rowTemplate}${i}`));
const cols = await row.findElements(By.className("dx-nowrap"));
let rowData = {};
for (let i = 0; i < cols.length; i++) {
const text = await cols[i].getText();
rowData[headerData[i]] = text;
}
courseMarks.push(rowData);
}
console.table(courseMarks, headerData);
} catch (error) {
console.log(error);
}
}
const { EMAIL, PASSWORD } = process.env;
init({ email: EMAIL, password: PASSWORD });