박시진

[Modifiy]Data input is possible

...@@ -3,29 +3,26 @@ function login(id, pw) { ...@@ -3,29 +3,26 @@ function login(id, pw) {
3 const crawler = async() => { 3 const crawler = async() => {
4 try{ 4 try{
5 const browser = await puppeteer.launch({headless: false, args:['--window-size=1920,1080']}); 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(); 6 const page = await browser.newPage();
8 await page.setViewport({ 7 await page.setViewport({
9 width:1920, 8 width:1920,
10 height:1080 9 height:1080
11 }) 10 })
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'); 11 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(() => { 12 + await page.type("#login_user_id", id);
14 - document.querySelector("#login_user_id").value = id 13 + await page.type("#login_user_password", pw);
15 - document.querySelector("#login_user_password").value = pw 14 + await page.click('#form1 > div > div.login_btn > a > span');
16 - document.querySelector('#form1 > div > div.login_btn > a > span').click(); 15 + 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 - }) 16 + return "Incorrect user ID or password."
18 - await page.waitForTimeout(500);
19 -
20 - }catch(err){
21 - console.log(err)
22 } 17 }
23 - if(page.url() === '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'){
24 - return "the account id or password you entered is incorrect";}
25 else { 18 else {
26 return `I got data { id:"${id}" pw:"${pw}" }`; 19 return `I got data { id:"${id}" pw:"${pw}" }`;
27 } 20 }
21 + }catch(err){
22 + console.log(err)
28 } 23 }
24 + }
25 +
29 crawler(); 26 crawler();
30 } 27 }
31 28
......