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-06-04 23:25:27 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2e83e2c602d1434fcdfc0a302abee5086678dd7e
2e83e2c6
1 parent
aca21452
[Add][Modify]Info Object
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
19 deletions
server/libs/E_Campus.js
server/libs/E_Campus.js
View file @
2e83e2c
const
puppeteer
=
require
(
"puppeteer"
);
//use puppeteer
Info
=
{
id
:
"null"
,
pw
:
"null"
,
peed
:
"null"
,
subjects
:
[]
}
function
setTimeoutPromise
(
ms
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -11,7 +17,7 @@ async function login(id, pw) {
try
{
//for visibility, headless: false
const
browser
=
await
puppeteer
.
launch
({
headless
:
tru
e
,
headless
:
fals
e
,
args
:
[
"--window-size=1920x1080"
,
"--start-maximized"
,
...
...
@@ -51,6 +57,11 @@ async function login(id, pw) {
// "#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()]);
const
promise1
=
Promise
.
resolve
();
promise1
.
then
(
value
=>
{
Info
.
id
=
id
;
Info
.
pw
=
pw
;
})
await
page
.
goto
(
"https://khcanvas.khu.ac.kr/"
);
return
page
;
}
...
...
@@ -69,24 +80,30 @@ async function getPeed(page) {
await
page
.
waitForSelector
(
selector
);
await
page
.
click
(
selector
);
// let data = {};
// let temp = await page.$("#calendar-feed-box-lower > a");
// data.name = await page.evaluate((data) => {
// return data.textContent;
// }, temp);
// data.link = await page.evaluate((data) => {
// return data.href;
// }, temp);
let
data
=
{};
let
temp
=
await
page
.
$
(
"#calendar-feed-box-lower > a"
);
const
feed
=
await
page
.
evaluate
((
data
)
=>
data
.
href
,
temp
);
data
.
name
=
await
page
.
evaluate
((
data
)
=>
{
return
data
.
textContent
;
},
temp
);
data
.
link
=
await
page
.
evaluate
((
data
)
=>
{
return
data
.
href
;
},
temp
);
// console.log(Promise.resolve(data));
const
promise2
=
Promise
.
resolve
(
data
.
link
);
promise2
.
then
(
value
=>
{
Info
.
peed
=
value
;
})
return
Promise
.
resolve
(
data
);
selector
=
"body > div:nth-child(9) > div.ui-dialog-titlebar.ui-widget-header.ui-corner-all.ui-helper-clearfix > button > span"
;
await
page
.
waitForSelector
(
selector
,
{
timeout
:
1000
});
await
page
.
click
(
selector
);
// let temp = await page.$("#calendar-feed-box-lower > a");
// const feed = await page.evaluate((data) => data.href, temp);
return
feed
;
// selector =
// "body > div:nth-child(9) > div.ui-dialog-titlebar.ui-widget-header.ui-corner-all.ui-helper-clearfix > button > span";
// await page.waitForSelector(selector, { timeout: 1000 });
// await page.click(selector);
// return feed;
}
async
function
getSubjects
(
page
)
{
...
...
@@ -102,6 +119,10 @@ async function getSubjects(page) {
for
(
let
index
=
0
;
index
<
number
;
index
++
)
{
data
.
push
(
await
getOne
(
page
,
index
+
1
));
}
// const promise1 = Promise.resolve(data);
// promise1.then(value => {
// Info.data = value;
// })
return
data
;
}
...
...
@@ -131,6 +152,23 @@ async function getOne(page, index) {
//}
// if your account is incorrect, value = [ '', '', 'Incorrect user ID or password.' ]
exports
.
login
=
login
;
exports
.
getPeed
=
getPeed
;
exports
.
getSubjects
=
getSubjects
;
// exports.login = login;
// exports.getPeed = getPeed;
// exports.getSubjects = getSubjects;
//console test
async
function
runrun
()
{
page
=
await
login
(
"lorem"
,
"lorem"
);
await
getPeed
(
page
);
// await getPeed(page).then((value => {
// console.log(value.link);
// }));
// await getSubjects(page);
console
.
log
(
Info
);
}
runrun
();
...
...
Please
register
or
login
to post a comment