test.js
5.2 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const express = require("express");
const router = express.Router();
const puppeteer = require("puppeteer")
const { getPeed, getSubjects, login, close } = require("./E_Campus.js");
async function runrun() {
page = await login("lorem", "lorem");
await getPeed(page);
await getSubjects(page);
Info = await close();
console.log(Info);
console.log(Info.subjects)
}
async function attendanceCheck(subject, code) {
try {
//for visibility, headless: false
browser = await puppeteer.launch({
headless: false,
args: [
"--window-size=1920x1080",
"--start-maximized",
"--no-sandbox",
"--disable-dev-shm-usage",
"--lang=ko",
],
});
const page = await browser.newPage();
await page.setViewport({
width: 1920,
height: 1080,
});
await page.goto(
"https://info21.khu.ac.kr/com/LoginCtr/login.do?returnurl=https://portal.khu.ac.kr/ksign/index.jsp?ssoGb=ptfol&sso=ok"
);
await page.type("#userId", Info.id);
await page.type("#userPw", Info.pw);
//press the login button on E_Campus homepage
await Promise.all([
page.click("#loginFrm > div > div.wrap > div.login_box > div.m_box.idx02.fr > button.btn.loginbtn1"),
page.waitForNavigation(),
]);
await page.goto(
"https://portal.khu.ac.kr/haksa/clss/clss/elctCrtf/index.do"
);
multipleClick(page);
await page.type("#crtfNo", code);
await page.click("#crtfBtn");
await page.click("body > div:nth-child(23) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button.di_btn_conf.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only");
await page.goto("https://portal.khu.ac.kr/haksa/clss/clss/elctCrtf/index.do");
result = await checkStatus(page);
console.log(result);
browser.close();
} catch (err) {
console.log(err);
}
}
async function multipleClick(page) {
let data = [];
let selector = "#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody";
const number = await page.$$eval(selector, (data) => data.length);
try{
for (let index = 2; index < number; index++) {
page.click(`#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr:nth-child("+ ${index} +") > td.first.input_td > a`)
}
page.click("#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first > td.first.input_td > a");
page.click("#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.last > td.first.input_td > a");
}
catch(err){
console.log("error!");
}
}
async function checkStatus(page) {
let selector = "#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody";
const number = await page.$$eval(selector, (data) => data.length);
for (let index = 2; index < number; index++) {
if (await getOne(page, index) == "인증완료"){
return "success";
}
else{
return "failed";
}
}
//exception(first context)
let temp = await page.$(
"#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first > td.first"
);
checking = await page.evaluate((data) => {
if (data.textContent == "인증완료"){
return "success";
}
else{
return "failed";
}
}, temp);
//exception(last context)
let templast = await page.$(
"#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.last > td.first"
);
checking = await page.evaluate((data) => {
if (data.textContent == "인증완료"){
return "success";
}
else{
return "failed";
}
}, templast);
}
async function getOne(page, index) {
let temp = await page.$(
"#baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr:nth-child("+index+ ") > td.first"
);
checking = await page.evaluate((data) => {
return data.textContent;
}, temp);
return Promise.resolve(checking);
}
async function test() {
await runrun();
await attendanceCheck("오픈소스SW개발", 2022);
}
test();
// //인증하기
// #baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first > td.first.input_td > a
// #baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first > td.first.input_td > a > span > b
// #baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.last > td.first
// //입력하기
// #crtfNo
// //인증 버튼 누르기
// #crtfBtn
// //확인
// body > div:nth-child(23) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button.di_btn_conf.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only
// //닫기
// body > div:nth-child(23) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button.di_btn_conf.ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only
// //인증완료
// #baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.first > td.first
// #baseForm > div:nth-child(3) > div.table_wrap.pc_view > table > tbody > tr.last > td.first
// .name 사용
// page