박시진

[Add][Modify]Info Object

1 const puppeteer = require("puppeteer"); 1 const puppeteer = require("puppeteer");
2 //use puppeteer 2 //use puppeteer
3 +Info = {
4 + id : "null",
5 + pw : "null",
6 + peed : "null",
7 + subjects : []
8 +}
3 9
4 function setTimeoutPromise(ms) { 10 function setTimeoutPromise(ms) {
5 return new Promise((resolve, reject) => { 11 return new Promise((resolve, reject) => {
...@@ -11,7 +17,7 @@ async function login(id, pw) { ...@@ -11,7 +17,7 @@ async function login(id, pw) {
11 try { 17 try {
12 //for visibility, headless: false 18 //for visibility, headless: false
13 const browser = await puppeteer.launch({ 19 const browser = await puppeteer.launch({
14 - headless: true, 20 + headless: false,
15 args: [ 21 args: [
16 "--window-size=1920x1080", 22 "--window-size=1920x1080",
17 "--start-maximized", 23 "--start-maximized",
...@@ -51,6 +57,11 @@ async function login(id, pw) { ...@@ -51,6 +57,11 @@ async function login(id, pw) {
51 // "#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a"; 57 // "#visual > div > div.xn-main-login-container > div:nth-child(2) > div.xn-main-link-wrap.xn-main-lms-link-wrap > a";
52 // await page.waitForSelector(selector); 58 // await page.waitForSelector(selector);
53 // await Promise.all([page.click(selector), page.waitForNavigation()]); 59 // await Promise.all([page.click(selector), page.waitForNavigation()]);
60 + const promise1 = Promise.resolve();
61 + promise1.then(value => {
62 + Info.id = id;
63 + Info.pw = pw;
64 + })
54 await page.goto("https://khcanvas.khu.ac.kr/"); 65 await page.goto("https://khcanvas.khu.ac.kr/");
55 return page; 66 return page;
56 } 67 }
...@@ -69,24 +80,30 @@ async function getPeed(page) { ...@@ -69,24 +80,30 @@ async function getPeed(page) {
69 await page.waitForSelector(selector); 80 await page.waitForSelector(selector);
70 await page.click(selector); 81 await page.click(selector);
71 82
72 - // let data = {}; 83 + let data = {};
73 - // let temp = await page.$("#calendar-feed-box-lower > a");
74 - // data.name = await page.evaluate((data) => {
75 - // return data.textContent;
76 - // }, temp);
77 - // data.link = await page.evaluate((data) => {
78 - // return data.href;
79 - // }, temp);
80 -
81 let temp = await page.$("#calendar-feed-box-lower > a"); 84 let temp = await page.$("#calendar-feed-box-lower > a");
82 - const feed = await page.evaluate((data) => data.href, temp); 85 + data.name = await page.evaluate((data) => {
86 + return data.textContent;
87 + }, temp);
88 + data.link = await page.evaluate((data) => {
89 + return data.href;
90 + }, temp);
91 + // console.log(Promise.resolve(data));
92 + const promise2 = Promise.resolve(data.link);
93 + promise2.then(value => {
94 + Info.peed = value;
95 + })
96 + return Promise.resolve(data);
83 97
84 - selector = 98 + // let temp = await page.$("#calendar-feed-box-lower > a");
85 - "body > div:nth-child(9) > div.ui-dialog-titlebar.ui-widget-header.ui-corner-all.ui-helper-clearfix > button > span"; 99 + // const feed = await page.evaluate((data) => data.href, temp);
86 - await page.waitForSelector(selector, { timeout: 1000 });
87 - await page.click(selector);
88 100
89 - return feed; 101 + // selector =
102 + // "body > div:nth-child(9) > div.ui-dialog-titlebar.ui-widget-header.ui-corner-all.ui-helper-clearfix > button > span";
103 + // await page.waitForSelector(selector, { timeout: 1000 });
104 + // await page.click(selector);
105 +
106 + // return feed;
90 } 107 }
91 108
92 async function getSubjects(page) { 109 async function getSubjects(page) {
...@@ -102,6 +119,10 @@ async function getSubjects(page) { ...@@ -102,6 +119,10 @@ async function getSubjects(page) {
102 for (let index = 0; index < number; index++) { 119 for (let index = 0; index < number; index++) {
103 data.push(await getOne(page, index + 1)); 120 data.push(await getOne(page, index + 1));
104 } 121 }
122 + // const promise1 = Promise.resolve(data);
123 + // promise1.then(value => {
124 + // Info.data = value;
125 + // })
105 return data; 126 return data;
106 } 127 }
107 128
...@@ -131,6 +152,23 @@ async function getOne(page, index) { ...@@ -131,6 +152,23 @@ async function getOne(page, index) {
131 //} 152 //}
132 // if your account is incorrect, value = [ '', '', 'Incorrect user ID or password.' ] 153 // if your account is incorrect, value = [ '', '', 'Incorrect user ID or password.' ]
133 154
134 -exports.login = login; 155 +// exports.login = login;
135 -exports.getPeed = getPeed; 156 +// exports.getPeed = getPeed;
136 -exports.getSubjects = getSubjects; 157 +// exports.getSubjects = getSubjects;
158 +
159 +
160 +
161 +//console test
162 +async function runrun() {
163 + page = await login("lorem", "lorem");
164 + await getPeed(page);
165 + // await getPeed(page).then((value => {
166 + // console.log(value.link);
167 + // }));
168 + // await getSubjects(page);
169 + console.log(Info);
170 +
171 +}
172 +runrun();
173 +
174 +
......