Showing
2 changed files
with
126 additions
and
30 deletions
... | @@ -32,7 +32,10 @@ async function loglogin(id, pw) { | ... | @@ -32,7 +32,10 @@ async function loglogin(id, pw) { |
32 | } | 32 | } |
33 | else { | 33 | else { |
34 | // return [id, pw, `I got data { id:"${id}" pw:"${pw}" }`]; | 34 | // return [id, pw, `I got data { id:"${id}" pw:"${pw}" }`]; |
35 | - return peedGet(page); | 35 | + await peedGet(page); |
36 | + await page.waitForTimeout(3000); | ||
37 | + await page.click('body > div:nth-child(9) > div.ui-dialog-titlebar.ui-widget-header.ui-corner-all.ui-helper-clearfix > button > span'); | ||
38 | + await subjectGet(page); | ||
36 | } | 39 | } |
37 | }catch(err){ | 40 | }catch(err){ |
38 | console.log(err) | 41 | console.log(err) |
... | @@ -61,7 +64,35 @@ async function peedGet(page) { | ... | @@ -61,7 +64,35 @@ async function peedGet(page) { |
61 | return Promise.resolve(data); | 64 | return Promise.resolve(data); |
62 | } | 65 | } |
63 | 66 | ||
64 | -//function that contact E_Campus | 67 | + |
68 | +async function subjectGet(page) { | ||
69 | + await page.waitForTimeout(5000); | ||
70 | + await page.click('#global_nav_courses_link > div.menu-item-icon-container > svg') | ||
71 | + await page.waitForTimeout(5000); | ||
72 | + let data= []; | ||
73 | + const number = await page.$$eval("#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li", (data) => data.length); | ||
74 | + for (let index = 0; index < number; index++) { | ||
75 | + data.push(await getOne(page, index + 1)); | ||
76 | + } | ||
77 | + console.log(Promise.resolve(data)); | ||
78 | +} | ||
79 | + | ||
80 | +async function getOne(page, index) { | ||
81 | + let data = {}; | ||
82 | + let temp = await page.$("#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li:nth-child(" + index + ") > a"); | ||
83 | + data.name = await page.evaluate((data) => { | ||
84 | + return data.textContent; | ||
85 | + }, temp); | ||
86 | + data.link = await page.evaluate((data) => { | ||
87 | + return data.href; | ||
88 | + }, temp); | ||
89 | + // 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); | ||
90 | + // 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); | ||
91 | + return Promise.resolve(data); | ||
92 | +} | ||
93 | + | ||
94 | + | ||
95 | +// function that contact E_Campus | ||
65 | // if your account is correct, value = Promise { | 96 | // if your account is correct, value = Promise { |
66 | // { name: '캘린더 피드를 보려면 클릭하세요.', | 97 | // { name: '캘린더 피드를 보려면 클릭하세요.', |
67 | // link: 'https://khcanvas.khu.ac.kr/feeds/calendars/user_~~~.ics' | 98 | // link: 'https://khcanvas.khu.ac.kr/feeds/calendars/user_~~~.ics' |
... | @@ -81,4 +112,4 @@ try { | ... | @@ -81,4 +112,4 @@ try { |
81 | 112 | ||
82 | login("2021105253", "qtw@@04271"); | 113 | login("2021105253", "qtw@@04271"); |
83 | 114 | ||
84 | -// export { login }; | 115 | +export { login }; | ... | ... |
1 | const puppeteer = require("puppeteer"); | 1 | const puppeteer = require("puppeteer"); |
2 | - function login(id, pw) { | 2 | +//use puppeteer |
3 | - const crawler = async() => { | 3 | + |
4 | +function setTimeoutPromise(ms) { | ||
5 | + return new Promise((resolve, reject) => { | ||
6 | + setTimeout(() => resolve(), ms); | ||
7 | + }); | ||
8 | +} | ||
9 | + | ||
10 | +async function loglogin(id, pw) { | ||
4 | try{ | 11 | try{ |
12 | + //for visibility, headless: false | ||
5 | const browser = await puppeteer.launch({headless: false, args:['--window-size=1920,1080']}); | 13 | const browser = await puppeteer.launch({headless: false, args:['--window-size=1920,1080']}); |
14 | + | ||
6 | const page = await browser.newPage(); | 15 | const page = await browser.newPage(); |
7 | - let information = {}; | ||
8 | await page.setViewport({ | 16 | await page.setViewport({ |
9 | width:1920, | 17 | width:1920, |
10 | height:1080 | 18 | height:1080 |
... | @@ -12,37 +20,94 @@ const puppeteer = require("puppeteer"); | ... | @@ -12,37 +20,94 @@ const puppeteer = require("puppeteer"); |
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'); | 20 | 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.type("#login_user_id", id); | 21 | await page.type("#login_user_id", id); |
14 | await page.type("#login_user_password", pw); | 22 | await page.type("#login_user_password", pw); |
23 | + | ||
24 | + //press the login button on E_Campus homepage | ||
15 | await page.click('#form1 > div > div.login_btn > a > span'); | 25 | await page.click('#form1 > div > div.login_btn > a > span'); |
26 | + await page.waitForTimeout(500); | ||
27 | + await setTimeoutPromise(1000); | ||
28 | + | ||
29 | + //When login is failed, return [id, pw, message] -> ["", "", "Incorrect~"] | ||
16 | if(page.url() === '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'){ | 30 | if(page.url() === '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'){ |
17 | - return ["", "", "Incorrect user ID or password."]; | 31 | + return ["", "", "Incorrect user ID or password."]; |
18 | } | 32 | } |
19 | else { | 33 | else { |
20 | - await page.waitForTimeout(5000); | 34 | + // return [id, pw, `I got data { id:"${id}" pw:"${pw}" }`]; |
21 | - // await page.goto('https://khcanvas.khu.ac.kr'); | 35 | + await peedGet(page); |
22 | - await page.click('#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a'); | 36 | + await page.waitForTimeout(3000); |
23 | - await page.waitForTimeout(500); | 37 | + await page.click('body > div:nth-child(9) > div.ui-dialog-titlebar.ui-widget-header.ui-corner-all.ui-helper-clearfix > button > span'); |
24 | - await page.click('#global_nav_calendar_link > div.menu-item-icon-container > svg'); | 38 | + await subjectGet(page); |
25 | - await page.waitForTimeout(10000); | 39 | + } |
26 | - await page.click('#calendar-feed > button'); | ||
27 | - let data = {}; | ||
28 | - let temp = await page.$('#calendar-feed-box-lower > a'); | ||
29 | - data.name = await page.evaluate((data) => { | ||
30 | - return data.textContent; | ||
31 | - }, temp); | ||
32 | - data.link = await page.evaluate((data) => { | ||
33 | - return data.href; | ||
34 | - }, temp); | ||
35 | - | ||
36 | - console.log(Promise.resolve(data)); | ||
37 | - | ||
38 | - } | ||
39 | }catch(err){ | 40 | }catch(err){ |
40 | console.log(err) | 41 | console.log(err) |
41 | } | 42 | } |
42 | - } | 43 | +} |
43 | 44 | ||
44 | - crawler(); | 45 | +//function that get your peed for your Ecampus calendar |
46 | +async function peedGet(page) { | ||
47 | + await page.waitForTimeout(5000); | ||
48 | + // await page.goto('https://khcanvas.khu.ac.kr'); | ||
49 | + await page.click('#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a'); | ||
50 | + await page.waitForTimeout(1000); | ||
51 | + await page.click('#global_nav_calendar_link > div.menu-item-icon-container > svg'); | ||
52 | + await page.waitForTimeout(10000); | ||
53 | + await page.click('#calendar-feed > button'); | ||
54 | + let data = {}; | ||
55 | + let temp = await page.$('#calendar-feed-box-lower > a'); | ||
56 | + data.name = await page.evaluate((data) => { | ||
57 | + return data.textContent; | ||
58 | + }, temp); | ||
59 | + data.link = await page.evaluate((data) => { | ||
60 | + return data.href; | ||
61 | + }, temp); | ||
62 | + | ||
63 | + console.log(Promise.resolve(data)); | ||
64 | + return Promise.resolve(data); | ||
65 | +} | ||
66 | + | ||
67 | + | ||
68 | +async function subjectGet(page) { | ||
69 | + await page.waitForTimeout(5000); | ||
70 | + await page.click('#global_nav_courses_link > div.menu-item-icon-container > svg') | ||
71 | + await page.waitForTimeout(5000); | ||
72 | + let data= []; | ||
73 | + const number = await page.$$eval("#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li", (data) => data.length); | ||
74 | + for (let index = 0; index < number; index++) { | ||
75 | + data.push(await getOne(page, index + 1)); | ||
76 | + } | ||
77 | + console.log(Promise.resolve(data)); | ||
78 | +} | ||
79 | + | ||
80 | +async function getOne(page, index) { | ||
81 | + let data = {}; | ||
82 | + let temp = await page.$("#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li:nth-child(" + index + ") > a"); | ||
83 | + data.name = await page.evaluate((data) => { | ||
84 | + return data.textContent; | ||
85 | + }, temp); | ||
86 | + data.link = await page.evaluate((data) => { | ||
87 | + return data.href; | ||
88 | + }, temp); | ||
89 | + // 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); | ||
90 | + // 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); | ||
91 | + return Promise.resolve(data); | ||
92 | +} | ||
93 | + | ||
94 | + | ||
95 | +// function that contact E_Campus | ||
96 | +// if your account is correct, value = Promise { | ||
97 | +// { name: '캘린더 피드를 보려면 클릭하세요.', | ||
98 | +// link: 'https://khcanvas.khu.ac.kr/feeds/calendars/user_~~~.ics' | ||
99 | +// } | ||
100 | +//} | ||
101 | +// if your account is incorrect, value = [ '', '', 'Incorrect user ID or password.' ] | ||
102 | +async function login(id, pw) { | ||
103 | + await setTimeoutPromise(1000); | ||
104 | +try { | ||
105 | + // value has the list ["","","Incorrect~"] | ||
106 | + const value = await loglogin(id, pw); | ||
107 | + console.log(value); | ||
108 | +} catch (e) { | ||
109 | + console.error(e); | ||
110 | + } | ||
45 | } | 111 | } |
46 | 112 | ||
47 | -login("lorem", "lorem"); | ||
48 | -console.log(login("lorem", "lorem")); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
113 | +login("2021105253", "qtw@@04271"); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment