박시진

[Add][Modify]Info Object

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: true,
headless: false,
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();
......