박시진

[Add]Close function [Modify]global object complete

......@@ -16,7 +16,7 @@ function setTimeoutPromise(ms) {
async function login(id, pw) {
try {
//for visibility, headless: false
const browser = await puppeteer.launch({
browser = await puppeteer.launch({
headless: false,
args: [
"--window-size=1920x1080",
......@@ -63,10 +63,11 @@ async function login(id, pw) {
Info.pw = pw;
})
await page.goto("https://khcanvas.khu.ac.kr/");
page = await getPeed(page);
await getSubjects(page);
await browser.close();
return Info;
// let currentPage = await getPeed(page);
// await getSubjects(currentPage);
// await browser.close();
// return Info;
return page;
}
} catch (err) {
console.log(err);
......@@ -110,6 +111,8 @@ async function getPeed(page) {
}
async function getSubjects(page) {
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.waitForTimeout(500);
await page.click(
"#global_nav_courses_link > div.menu-item-icon-container > svg"
);
......@@ -122,10 +125,6 @@ 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;
// })
const promise3 = Promise.resolve(data);
promise3.then(value => {
Info.subjects = value;
......@@ -151,6 +150,9 @@ async function getOne(page, index) {
return Promise.resolve(data);
}
async function close() {
browser.close();
}
// function that contact E_Campus
// if your account is correct, value = Promise {
// { name: '캘린더 피드를 보려면 클릭하세요.',
......@@ -166,13 +168,13 @@ exports.login = login;
//console test
// async function runrun() {
// page = await login("lorem", "lorem");
// await getPeed(page);
// await getSubjects(page);
// console.log(Info);
// }
// runrun();
async function runrun() {
page = await login("2021105253", "lorem");
await getPeed(page);
await getSubjects(page);
await close();
console.log(Info);
}
runrun();
......