Toggle navigation
Toggle navigation
This project
Loading...
Sign in
HyeonJun Jeon
/
Extended-Calendar
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박시진
2022-05-30 04:25:50 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8017d850af56d6a4bf6d29d6d53a7c68bc990f5a
8017d850
1 parent
6f623eab
Login function using puppeteer
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
1 deletions
package-lock.json
package.json
src/libs/E_Campus.js
package-lock.json
View file @
8017d85
This diff is collapsed. Click to expand it.
package.json
View file @
8017d85
...
...
@@ -7,6 +7,7 @@
"@testing-library/react"
:
"^13.2.0"
,
"@testing-library/user-event"
:
"^13.5.0"
,
"localforage"
:
"^1.10.0"
,
"puppeteer"
:
"^14.1.1"
,
"react"
:
"^18.1.0"
,
"react-dom"
:
"^18.1.0"
,
"react-router-dom"
:
"^6.3.0"
,
...
...
src/libs/E_Campus.js
View file @
8017d85
function
login
(
id
,
pw
)
{
return
`I got data { id:"
${
id
}
" pw:"
${
pw
}
" }`
;
const
crawler
=
async
()
=>
{
try
{
const
browser
=
await
puppeteer
.
launch
({
headless
:
false
,
args
:[
'--window-size=1920,1080'
]});
// for observing the process of login, headless -> false
const
page
=
await
browser
.
newPage
();
await
page
.
setViewport
({
width
:
1920
,
height
:
1080
})
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'
);
await
page
.
evaluate
(()
=>
{
document
.
querySelector
(
"#login_user_id"
).
value
=
id
document
.
querySelector
(
"#login_user_password"
).
value
=
pw
document
.
querySelector
(
'#form1 > div > div.login_btn > a > span'
).
click
();
})
}
catch
(
err
){
console
.
log
(
err
)
}
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'
){
return
"the account id or password you entered is incorrect"
;}
else
{
return
`I got data { id:"
${
id
}
" pw:"
${
pw
}
" }`
;
}
}
crawler
();
}
export
{
login
};
...
...
Please
register
or
login
to post a comment