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 18:14:15 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2fdbf518b7d4ed23a8b84ac9174067e563a55e24
2fdbf518
1 parent
b9fb3bf7
[Add]Remark [Modify]connection information
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
14 deletions
src/libs/E_Campus.js
src/libs/E_Campus_loginTest.js
src/libs/E_Campus.js
View file @
2fdbf51
const
puppeteer
=
require
(
"puppeteer"
);
function
login
(
id
,
pw
)
{
const
crawler
=
async
()
=>
{
//use puppeteer
function
setTimeoutPromise
(
ms
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
setTimeout
(()
=>
resolve
(),
ms
);
});
}
async
function
loglogin
(
id
,
pw
)
{
try
{
//for visibility, headless: false
const
browser
=
await
puppeteer
.
launch
({
headless
:
false
,
args
:[
'--window-size=1920,1080'
]});
const
page
=
await
browser
.
newPage
();
await
page
.
setViewport
({
width
:
1920
,
...
...
@@ -11,19 +20,32 @@ function login(id, pw) {
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
.
type
(
"#login_user_id"
,
id
);
await
page
.
type
(
"#login_user_password"
,
pw
);
//press the login button on E_Campus homepage
await
page
.
click
(
'#form1 > div > div.login_btn > a > span'
);
await
page
.
waitForTimeout
(
500
);
await
setTimeoutPromise
(
1000
);
//When login is failed, return [id, pw, message] -> ["", "", "Incorrect~"]
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'
){
return
"Incorrect user ID or password."
return
[
""
,
""
,
"Incorrect user ID or password."
];
}
else
{
return
`I got data { id:"
${
id
}
" pw:"
${
pw
}
" }`
;
return
[
id
,
pw
,
`I got data { id:"
${
id
}
" pw:"
${
pw
}
" }`
];
}
}
catch
(
err
){
console
.
log
(
err
)
}
}
async
function
login
(
id
,
pw
)
{
await
setTimeoutPromise
(
1000
);
try
{
// value has the list ["","","Incorrect~"] or [id, pw, "I got data~"]
const
value
=
await
loglogin
(
id
,
pw
);
console
.
log
(
value
[
2
]);
}
catch
(
e
)
{
console
.
error
(
e
);
}
crawler
();
}
export
{
login
};
...
...
src/libs/E_Campus_loginTest.js
View file @
2fdbf51
//The prototype
// const puppeteer = require("puppeteer");
// 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 = //자신의 E_Campus account id
// document.querySelector("#login_user_password").value = // pw
// document.querySelector('#form1 > div > div.login_btn > a > span').click();
// })
// }catch(err){
// console.log(err)
// }
// }
// crawler();
//The test on nodejs (evaluate version for using input data)
const
puppeteer
=
require
(
"puppeteer"
);
//Example for not using user_input_login_information
const
id
=
"lorem"
;
const
pw
=
"lorem"
;
const
informationList
=
new
Object
();
function
setTimeoutPromise
(
ms
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
setTimeout
(()
=>
resolve
(),
ms
);
});
}
const
crawler
=
async
()
=>
{
async
function
loglogin
(
id
,
pw
)
{
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
=
//자신의 E_Campus account id
document
.
querySelector
(
"#login_user_password"
).
value
=
// pw
document
.
querySelector
(
'#form1 > div > div.login_btn > a > span'
).
click
(
);
})
await
page
.
type
(
"#login_user_id"
,
id
);
await
page
.
type
(
"#login_user_password"
,
pw
);
await
page
.
click
(
'#form1 > div > div.login_btn > a > span'
);
await
page
.
waitForTimeout
(
500
);
await
setTimeoutPromise
(
1000
);
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'
){
return
[
""
,
""
,
"Incorrect user ID or password."
];
}
else
{
return
[
id
,
pw
,
`I got data { id:"
${
id
}
" pw:"
${
pw
}
" }`
];
}
}
catch
(
err
){
console
.
log
(
err
)
}
}
async
function
login
(
id
,
pw
)
{
await
setTimeoutPromise
(
1000
);
try
{
const
value
=
await
loglogin
(
id
,
pw
);
// promise1.then
console
.
log
(
"Id : "
+
value
[
0
]
+
", password : "
+
value
[
1
]
+
", message : "
+
value
[
2
]);
return
value
[
2
];
}
catch
(
e
)
{
console
.
error
(
e
);
}
}
login
(
id
,
pw
);
//[id : , pw : , message : "Incorrect user ID or password."]
crawler
();
\ No newline at end of file
...
...
Please
register
or
login
to post a comment