HyeonJun Jeon

[Del] Unused file

1 -//The prototype
2 -// const puppeteer = require("puppeteer");
3 -// const crawler = async() => {
4 -// try{
5 -// const browser = await puppeteer.launch({headless: false, args:['--window-size=1920,1080']});
6 -// // for observing the process of login, headless -> false
7 -// const page = await browser.newPage();
8 -// await page.setViewport({
9 -// width:1920,
10 -// height:1080
11 -// })
12 -// await page.goto('https://e-campus.khu.ac.kr/xn-sso/login.php?auto_login=&sso_only=&cvs_lgn=&return_url=https%3A%2F%2Fe-campus.khu.ac.kr%2Fxn-sso%2Fgw-cb.php%3Ffrom%3D%26login_type%3Dstandalone%26return_url%3Dhttps%253A%252F%252Fe-campus.khu.ac.kr%252Flogin%252Fcallback');
13 -// await page.evaluate(() => {
14 -// document.querySelector("#login_user_id").value = //자신의 E_Campus account id
15 -// document.querySelector("#login_user_password").value = // pw
16 -// document.querySelector('#form1 > div > div.login_btn > a > span').click();
17 -// })
18 -// }catch(err){
19 -// console.log(err)
20 -// }
21 -// }
22 -// crawler();
23 -
24 -//The test on nodejs (evaluate version for using input data)
25 -const puppeteer = require("puppeteer");
26 -//Example for not using user_input_login_information
27 -const id = "lorem";
28 -const pw = "lorem";
29 -const informationList = new Object();
30 -
31 -function setTimeoutPromise(ms) {
32 - return new Promise((resolve, reject) => {
33 - setTimeout(() => resolve(), ms);
34 - });
35 -}
36 -
37 -async function loglogin(id, pw) {
38 - try {
39 - const browser = await puppeteer.launch({
40 - headless: false,
41 - args: ["--window-size=1920,1080"],
42 - });
43 - const page = await browser.newPage();
44 - await page.setViewport({
45 - width: 1920,
46 - height: 1080,
47 - });
48 - await page.goto(
49 - "https://e-campus.khu.ac.kr/xn-sso/login.php?auto_login=&sso_only=&cvs_lgn=&return_url=https%3A%2F%2Fe-campus.khu.ac.kr%2Fxn-sso%2Fgw-cb.php%3Ffrom%3D%26login_type%3Dstandalone%26return_url%3Dhttps%253A%252F%252Fe-campus.khu.ac.kr%252Flogin%252Fcallback"
50 - );
51 - await page.type("#login_user_id", id);
52 - await page.type("#login_user_password", pw);
53 - await page.click("#form1 > div > div.login_btn > a > span");
54 - await page.waitForTimeout(500);
55 - await setTimeoutPromise(1000);
56 -
57 - if (
58 - page.url() ===
59 - "https://e-campus.khu.ac.kr/xn-sso/gw-cb.php?from=&login_type=standalone&return_url=https%3A%2F%2Fe-campus.khu.ac.kr%2Flogin%2Fcallback"
60 - ) {
61 - return ["", "", "Incorrect user ID or password."];
62 - } else {
63 - return [id, pw, `I got data { id:"${id}" pw:"${pw}" }`];
64 - }
65 - } catch (err) {
66 - console.log(err);
67 - }
68 -}
69 -async function login(id, pw) {
70 - await setTimeoutPromise(1000);
71 - try {
72 - const value = await loglogin(id, pw);
73 - // promise1.then
74 - console.log(
75 - "Id : " +
76 - value[0] +
77 - ", password : " +
78 - value[1] +
79 - ", message : " +
80 - value[2]
81 - );
82 - return value[2];
83 - } catch (e) {
84 - console.error(e);
85 - }
86 -}
87 -
88 -login(id, pw);
89 -//[id : , pw : , message : "Incorrect user ID or password."]
1 -const puppeteer = require("puppeteer");
2 -//use puppeteer
3 -
4 -function setTimeoutPromise(ms) {
5 - return new Promise((resolve, reject) => {
6 - setTimeout(() => resolve(), ms);
7 - });
8 -}
9 -
10 -async function loglogin(id, pw) {
11 - try {
12 - //for visibility, headless: false
13 - const browser = await puppeteer.launch({
14 - headless: false,
15 - args: ["--window-size=1920,1080"],
16 - });
17 -
18 - const page = await browser.newPage();
19 - await page.setViewport({
20 - width: 1920,
21 - height: 1080,
22 - });
23 - await page.goto(
24 - "https://e-campus.khu.ac.kr/xn-sso/login.php?auto_login=&sso_only=&cvs_lgn=&return_url=https%3A%2F%2Fe-campus.khu.ac.kr%2Fxn-sso%2Fgw-cb.php%3Ffrom%3D%26login_type%3Dstandalone%26return_url%3Dhttps%253A%252F%252Fe-campus.khu.ac.kr%252Flogin%252Fcallback"
25 - );
26 - await page.type("#login_user_id", id);
27 - await page.type("#login_user_password", pw);
28 -
29 - //press the login button on E_Campus homepage
30 - await page.click("#form1 > div > div.login_btn > a > span");
31 - await page.waitForTimeout(500);
32 - await setTimeoutPromise(1000);
33 -
34 - //When login is failed, return [id, pw, message] -> ["", "", "Incorrect~"]
35 - if (
36 - page.url() ===
37 - "https://e-campus.khu.ac.kr/xn-sso/gw-cb.php?from=&login_type=standalone&return_url=https%3A%2F%2Fe-campus.khu.ac.kr%2Flogin%2Fcallback"
38 - ) {
39 - return ["", "", "Incorrect user ID or password."];
40 - } else {
41 - // return [id, pw, `I got data { id:"${id}" pw:"${pw}" }`];
42 - await peedGet(page);
43 - await page.waitForTimeout(3000);
44 - await page.click(
45 - "body > div:nth-child(9) > div.ui-dialog-titlebar.ui-widget-header.ui-corner-all.ui-helper-clearfix > button > span"
46 - );
47 - await subjectGet(page);
48 - }
49 - } catch (err) {
50 - console.log(err);
51 - }
52 -}
53 -
54 -//function that get your peed for your Ecampus calendar
55 -async function peedGet(page) {
56 - await page.waitForTimeout(5000);
57 - // await page.goto('https://khcanvas.khu.ac.kr');
58 - await page.click(
59 - "#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a"
60 - );
61 - await page.waitForTimeout(1000);
62 - await page.click(
63 - "#global_nav_calendar_link > div.menu-item-icon-container > svg"
64 - );
65 - await page.waitForTimeout(10000);
66 - await page.click("#calendar-feed > button");
67 - let data = {};
68 - let temp = await page.$("#calendar-feed-box-lower > a");
69 - data.name = await page.evaluate((data) => {
70 - return data.textContent;
71 - }, temp);
72 - data.link = await page.evaluate((data) => {
73 - return data.href;
74 - }, temp);
75 -
76 - console.log(data);
77 - return data;
78 -}
79 -
80 -async function subjectGet(page) {
81 - await page.waitForTimeout(5000);
82 - await page.click(
83 - "#global_nav_courses_link > div.menu-item-icon-container > svg"
84 - );
85 - await page.waitForTimeout(5000);
86 - let data = [];
87 - const number = await page.$$eval(
88 - "#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li",
89 - (data) => data.length
90 - );
91 - for (let index = 0; index < number; index++) {
92 - data.push(await getOne(page, index + 1));
93 - }
94 - console.log(data);
95 -}
96 -
97 -async function getOne(page, index) {
98 - let data = {};
99 - let temp = await page.$(
100 - "#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li:nth-child(" +
101 - index +
102 - ") > a"
103 - );
104 - data.name = await page.evaluate((data) => {
105 - return data.textContent;
106 - }, temp);
107 - data.link = await page.evaluate((data) => {
108 - return data.href;
109 - }, temp);
110 - // data.subjectName = await page.$eval("#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li:nth-child(" + index + ") > a", (data) => data.textContent);
111 - // data.subjectLink = await page.$eval("#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li:nth-child(" + index + ") > a", (data) => data.href);
112 - return data;
113 -}
114 -
115 -// function that contact E_Campus
116 -// if your account is correct, value = Promise {
117 -// { name: '캘린더 피드를 보려면 클릭하세요.',
118 -// link: 'https://khcanvas.khu.ac.kr/feeds/calendars/user_~~~.ics'
119 -// }
120 -//}
121 -// if your account is incorrect, value = [ '', '', 'Incorrect user ID or password.' ]
122 -async function login(id, pw) {
123 - await setTimeoutPromise(1000);
124 - try {
125 - // value has the list ["","","Incorrect~"]
126 - const value = await loglogin(id, pw);
127 - console.log(value);
128 - } catch (e) {
129 - console.error(e);
130 - }
131 -}
132 -
133 -// login("2021105253", "qtw@@04271");