Showing
3 changed files
with
29 additions
and
1 deletions
This diff is collapsed. Click to expand it.
... | @@ -7,6 +7,7 @@ | ... | @@ -7,6 +7,7 @@ |
7 | "@testing-library/react": "^13.2.0", | 7 | "@testing-library/react": "^13.2.0", |
8 | "@testing-library/user-event": "^13.5.0", | 8 | "@testing-library/user-event": "^13.5.0", |
9 | "localforage": "^1.10.0", | 9 | "localforage": "^1.10.0", |
10 | + "puppeteer": "^14.1.1", | ||
10 | "react": "^18.1.0", | 11 | "react": "^18.1.0", |
11 | "react-dom": "^18.1.0", | 12 | "react-dom": "^18.1.0", |
12 | "react-router-dom": "^6.3.0", | 13 | "react-router-dom": "^6.3.0", | ... | ... |
1 | function login(id, pw) { | 1 | function login(id, pw) { |
2 | - return `I got data { id:"${id}" pw:"${pw}" }`; | 2 | + const crawler = async() => { |
3 | + try{ | ||
4 | + const browser = await puppeteer.launch({headless: false, args:['--window-size=1920,1080']}); | ||
5 | + // for observing the process of login, headless -> false | ||
6 | + const page = await browser.newPage(); | ||
7 | + await page.setViewport({ | ||
8 | + width:1920, | ||
9 | + height:1080 | ||
10 | + }) | ||
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'); | ||
12 | + await page.evaluate(() => { | ||
13 | + document.querySelector("#login_user_id").value = id | ||
14 | + document.querySelector("#login_user_password").value = pw | ||
15 | + document.querySelector('#form1 > div > div.login_btn > a > span').click(); | ||
16 | + }) | ||
17 | + | ||
18 | + }catch(err){ | ||
19 | + console.log(err) | ||
20 | + } | ||
21 | + 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'){ | ||
22 | + return "the account id or password you entered is incorrect";} | ||
23 | + else { | ||
24 | + return `I got data { id:"${id}" pw:"${pw}" }`; | ||
25 | + } | ||
26 | + } | ||
27 | + crawler(); | ||
3 | } | 28 | } |
4 | 29 | ||
5 | export { login }; | 30 | export { login }; |
31 | + | ||
32 | + | ... | ... |
-
Please register or login to post a comment