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
HyeonJun Jeon
2022-06-02 23:03:24 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d305ac8ad5e4ebfa23b83a92707909236419101e
d305ac8a
1 parent
cb1f79cc
[FIx] Await, Module
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
58 deletions
package.json
server/libs/E_Campus.js
server/libs/E_Campus_loginTest.js
server/libs/E_Campus_login_getPeed.js
server/server.js
package.json
View file @
d305ac8
...
...
@@ -41,6 +41,5 @@
"last 1 firefox version"
,
"last 1 safari version"
]
},
"type"
:
"module"
}
}
...
...
server/libs/E_Campus.js
View file @
d305ac8
import
puppeteer
from
"puppeteer"
;
const
puppeteer
=
require
(
"puppeteer"
)
;
//use puppeteer
function
setTimeoutPromise
(
ms
)
{
...
...
@@ -39,6 +39,12 @@ async function login(id, pw) {
)
{
return
false
;
}
else
{
// await page.goto('https://khcanvas.khu.ac.kr');
let
selector
=
"#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a"
;
await
page
.
waitForSelector
(
selector
);
await
Promise
.
all
([
page
.
click
(
selector
),
page
.
waitForNavigation
()]);
return
page
;
}
}
catch
(
err
)
{
...
...
@@ -50,19 +56,14 @@ async function login(id, pw) {
//function that get your peed for your Ecampus calendar
async
function
getPeed
(
page
)
{
console
.
log
(
"getPeed"
);
// await page.goto('https://khcanvas.khu.ac.kr');
let
selector
=
"#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a"
;
await
page
.
waitForSelector
(
selector
);
await
page
.
click
(
selector
);
selector
=
"#global_nav_calendar_link > div.menu-item-icon-container > svg"
;
await
page
.
waitForSelector
(
selector
);
page
.
click
(
selector
);
await
page
.
click
(
selector
);
selector
=
"#calendar-feed > button"
;
await
page
.
waitForSelector
(
selector
);
page
.
click
(
selector
);
await
page
.
click
(
selector
);
// let data = {};
// let temp = await page.$("#calendar-feed-box-lower > a");
...
...
@@ -127,4 +128,6 @@ async function getOne(page, index) {
//}
// if your account is incorrect, value = [ '', '', 'Incorrect user ID or password.' ]
export
{
login
,
getPeed
,
getSubjects
};
exports
.
login
=
login
;
exports
.
getPeed
=
getPeed
;
exports
.
getSubjects
=
getSubjects
;
...
...
server/libs/E_Campus_loginTest.js
View file @
d305ac8
//The prototype
//
import puppeteer from "puppeteer"
;
//
const puppeteer = require("puppeteer")
;
// const crawler = async() => {
// try{
// const browser = await puppeteer.launch({headless: false, args:['--window-size=1920,1080']});
...
...
@@ -21,7 +21,6 @@
// }
// crawler();
//The test on nodejs (evaluate version for using input data)
const
puppeteer
=
require
(
"puppeteer"
);
//Example for not using user_input_login_information
...
...
@@ -36,28 +35,35 @@ function setTimeoutPromise(ms) {
}
async
function
loglogin
(
id
,
pw
)
{
try
{
const
browser
=
await
puppeteer
.
launch
({
headless
:
false
,
args
:[
'--window-size=1920,1080'
]});
try
{
const
browser
=
await
puppeteer
.
launch
({
headless
:
false
,
args
:
[
"--window-size=1920,1080"
],
});
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'
);
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
.
type
(
"#login_user_id"
,
id
);
await
page
.
type
(
"#login_user_password"
,
pw
);
await
page
.
click
(
'#form1 > div > div.login_btn > a > span'
);
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'
){
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
{
}
else
{
return
[
id
,
pw
,
`I got data { id:"
${
id
}
" pw:"
${
pw
}
" }`
];
}
}
catch
(
err
)
{
console
.
log
(
err
)
}
catch
(
err
)
{
console
.
log
(
err
);
}
}
async
function
login
(
id
,
pw
)
{
...
...
@@ -65,10 +71,15 @@ async function login(id, pw) {
try
{
const
value
=
await
loglogin
(
id
,
pw
);
// promise1.then
console
.
log
(
"Id : "
+
value
[
0
]
+
", password : "
+
value
[
1
]
+
", message : "
+
value
[
2
]);
console
.
log
(
"Id : "
+
value
[
0
]
+
", password : "
+
value
[
1
]
+
", message : "
+
value
[
2
]
);
return
value
[
2
];
}
catch
(
e
)
{
console
.
error
(
e
);
}
...
...
@@ -76,4 +87,3 @@ async function login(id, pw) {
login
(
id
,
pw
);
//[id : , pw : , message : "Incorrect user ID or password."]
...
...
server/libs/E_Campus_login_getPeed.js
View file @
d305ac8
import
puppeteer
from
"puppeteer"
;
const
puppeteer
=
require
(
"puppeteer"
)
;
//use puppeteer
function
setTimeoutPromise
(
ms
)
{
...
...
@@ -8,37 +8,46 @@ function setTimeoutPromise(ms) {
}
async
function
loglogin
(
id
,
pw
)
{
try
{
try
{
//for visibility, headless: false
const
browser
=
await
puppeteer
.
launch
({
headless
:
false
,
args
:[
'--window-size=1920,1080'
]});
const
browser
=
await
puppeteer
.
launch
({
headless
:
false
,
args
:
[
"--window-size=1920,1080"
],
});
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'
);
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
.
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
.
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'
){
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
{
}
else
{
// return [id, pw, `I got data { id:"${id}" pw:"${pw}" }`];
await
peedGet
(
page
);
await
page
.
waitForTimeout
(
3000
);
await
page
.
click
(
'body > div:nth-child(9) > div.ui-dialog-titlebar.ui-widget-header.ui-corner-all.ui-helper-clearfix > button > span'
);
await
page
.
click
(
"body > div:nth-child(9) > div.ui-dialog-titlebar.ui-widget-header.ui-corner-all.ui-helper-clearfix > button > span"
);
await
subjectGet
(
page
);
}
}
catch
(
err
)
{
console
.
log
(
err
)
}
catch
(
err
)
{
console
.
log
(
err
);
}
}
...
...
@@ -46,13 +55,17 @@ async function loglogin(id, pw) {
async
function
peedGet
(
page
)
{
await
page
.
waitForTimeout
(
5000
);
// await page.goto('https://khcanvas.khu.ac.kr');
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'
);
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"
);
await
page
.
waitForTimeout
(
1000
);
await
page
.
click
(
'#global_nav_calendar_link > div.menu-item-icon-container > svg'
);
await
page
.
click
(
"#global_nav_calendar_link > div.menu-item-icon-container > svg"
);
await
page
.
waitForTimeout
(
10000
);
await
page
.
click
(
'#calendar-feed > button'
);
await
page
.
click
(
"#calendar-feed > button"
);
let
data
=
{};
let
temp
=
await
page
.
$
(
'#calendar-feed-box-lower > a'
);
let
temp
=
await
page
.
$
(
"#calendar-feed-box-lower > a"
);
data
.
name
=
await
page
.
evaluate
((
data
)
=>
{
return
data
.
textContent
;
},
temp
);
...
...
@@ -64,13 +77,17 @@ async function peedGet(page) {
return
data
;
}
async
function
subjectGet
(
page
)
{
await
page
.
waitForTimeout
(
5000
);
await
page
.
click
(
'#global_nav_courses_link > div.menu-item-icon-container > svg'
)
await
page
.
click
(
"#global_nav_courses_link > div.menu-item-icon-container > svg"
);
await
page
.
waitForTimeout
(
5000
);
let
data
=
[];
const
number
=
await
page
.
$$eval
(
"#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li"
,
(
data
)
=>
data
.
length
);
let
data
=
[];
const
number
=
await
page
.
$$eval
(
"#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li"
,
(
data
)
=>
data
.
length
);
for
(
let
index
=
0
;
index
<
number
;
index
++
)
{
data
.
push
(
await
getOne
(
page
,
index
+
1
));
}
...
...
@@ -79,7 +96,11 @@ async function subjectGet(page) {
async
function
getOne
(
page
,
index
)
{
let
data
=
{};
let
temp
=
await
page
.
$
(
"#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li:nth-child("
+
index
+
") > a"
);
let
temp
=
await
page
.
$
(
"#nav-tray-portal > span > span > div > div > div > div > div > ul:nth-child(3) > li:nth-child("
+
index
+
") > a"
);
data
.
name
=
await
page
.
evaluate
((
data
)
=>
{
return
data
.
textContent
;
},
temp
);
...
...
@@ -91,7 +112,6 @@ async function getOne(page, index) {
return
data
;
}
// function that contact E_Campus
// if your account is correct, value = Promise {
// { name: '캘린더 피드를 보려면 클릭하세요.',
...
...
@@ -101,11 +121,11 @@ async function getOne(page, index) {
// if your account is incorrect, value = [ '', '', 'Incorrect user ID or password.' ]
async
function
login
(
id
,
pw
)
{
await
setTimeoutPromise
(
1000
);
try
{
try
{
// value has the list ["","","Incorrect~"]
const
value
=
await
loglogin
(
id
,
pw
);
console
.
log
(
value
);
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
error
(
e
);
}
}
...
...
server/server.js
View file @
d305ac8
import
express
from
"express"
;
import
{
getPeed
,
getSubjects
,
login
}
from
"./libs/E_Campus.js"
;
import
fs
from
"fs"
;
const
express
=
require
(
"express"
)
;
const
{
getPeed
,
getSubjects
,
login
}
=
require
(
"./libs/E_Campus.js"
)
;
const
fs
=
require
(
"fs"
)
;
const
app
=
express
();
const
router
=
express
.
Router
();
router
.
get
(
"/"
,
(
req
,
res
)
=>
{
console
.
log
(
req
);
res
.
header
(
"Access-Control-Allow-Origin"
,
"http://localhost:3000"
);
res
.
send
({
test
:
"Hi"
});
console
.
log
(
"listened /"
);
...
...
@@ -30,3 +31,7 @@ fs.readFile("server/libs/login.pvdata", "utf8", async (err, data) => {
});
}
else
console
.
log
(
"Incorrect user ID or password."
);
});
// app.listen(3001, function () {
// console.log("listening on 3001");
// });
...
...
Please
register
or
login
to post a comment