[Add]New file for testing on nodejs [Modify]E_Campus.js + peedGet function
Showing
2 changed files
with
87 additions
and
6 deletions
| ... | @@ -31,21 +31,54 @@ async function loglogin(id, pw) { | ... | @@ -31,21 +31,54 @@ async function loglogin(id, pw) { |
| 31 | return ["", "", "Incorrect user ID or password."]; | 31 | return ["", "", "Incorrect user ID or password."]; |
| 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 | } | 36 | } |
| 36 | }catch(err){ | 37 | }catch(err){ |
| 37 | console.log(err) | 38 | console.log(err) |
| 38 | } | 39 | } |
| 39 | } | 40 | } |
| 41 | + | ||
| 42 | +//function that get your peed for your Ecampus calendar | ||
| 43 | +async function peedGet(page) { | ||
| 44 | + await page.waitForTimeout(5000); | ||
| 45 | + // await page.goto('https://khcanvas.khu.ac.kr'); | ||
| 46 | + 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'); | ||
| 47 | + await page.waitForTimeout(1000); | ||
| 48 | + await page.click('#global_nav_calendar_link > div.menu-item-icon-container > svg'); | ||
| 49 | + await page.waitForTimeout(10000); | ||
| 50 | + await page.click('#calendar-feed > button'); | ||
| 51 | + let data = {}; | ||
| 52 | + let temp = await page.$('#calendar-feed-box-lower > a'); | ||
| 53 | + data.name = await page.evaluate((data) => { | ||
| 54 | + return data.textContent; | ||
| 55 | + }, temp); | ||
| 56 | + data.link = await page.evaluate((data) => { | ||
| 57 | + return data.href; | ||
| 58 | + }, temp); | ||
| 59 | + | ||
| 60 | + console.log(Promise.resolve(data)); | ||
| 61 | + return Promise.resolve(data); | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +//function that contact E_Campus | ||
| 65 | +// if your account is correct, value = Promise { | ||
| 66 | +// { name: '캘린더 피드를 보려면 클릭하세요.', | ||
| 67 | +// link: 'https://khcanvas.khu.ac.kr/feeds/calendars/user_~~~.ics' | ||
| 68 | +// } | ||
| 69 | +//} | ||
| 70 | +// if your account is incorrect, value = [ '', '', 'Incorrect user ID or password.' ] | ||
| 40 | async function login(id, pw) { | 71 | async function login(id, pw) { |
| 41 | await setTimeoutPromise(1000); | 72 | await setTimeoutPromise(1000); |
| 42 | - try { | 73 | +try { |
| 43 | - // value has the list ["","","Incorrect~"] or [id, pw, "I got data~"] | 74 | + // value has the list ["","","Incorrect~"] |
| 44 | const value = await loglogin(id, pw); | 75 | const value = await loglogin(id, pw); |
| 45 | - console.log(value[2]); | 76 | + console.log(value); |
| 46 | - } catch (e) { | 77 | +} catch (e) { |
| 47 | console.error(e); | 78 | console.error(e); |
| 48 | } | 79 | } |
| 49 | } | 80 | } |
| 50 | 81 | ||
| 51 | -export { login }; | 82 | +login("2021105253", "qtw@@04271"); |
| 83 | + | ||
| 84 | +// export { login }; | ... | ... |
src/libs/E_Campus_login_getPeed.js
0 → 100644
| 1 | +const puppeteer = require("puppeteer"); | ||
| 2 | + function login(id, pw) { | ||
| 3 | + const crawler = async() => { | ||
| 4 | + try{ | ||
| 5 | + const browser = await puppeteer.launch({headless: false, args:['--window-size=1920,1080']}); | ||
| 6 | + const page = await browser.newPage(); | ||
| 7 | + let information = {}; | ||
| 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.type("#login_user_id", id); | ||
| 14 | + await page.type("#login_user_password", pw); | ||
| 15 | + await page.click('#form1 > div > div.login_btn > a > span'); | ||
| 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'){ | ||
| 17 | + return ["", "", "Incorrect user ID or password."]; | ||
| 18 | + } | ||
| 19 | + else { | ||
| 20 | + await page.waitForTimeout(5000); | ||
| 21 | + // await page.goto('https://khcanvas.khu.ac.kr'); | ||
| 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'); | ||
| 23 | + await page.waitForTimeout(500); | ||
| 24 | + await page.click('#global_nav_calendar_link > div.menu-item-icon-container > svg'); | ||
| 25 | + await page.waitForTimeout(10000); | ||
| 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 | + console.log(err) | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + crawler(); | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +login("lorem", "lorem"); | ||
| 48 | +console.log(login("lorem", "lorem")); | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment