everytime_crawling.js
2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const et_id = "";
const et_pw = "";
const lecture = "";
await page.goto('https://everytime.kr/login');
await page.evaluate((id, pw) => {
document.querySelector("input[name=userid]").value = id;
document.querySelector("input[name=password]").value = pw;
}, et_id, et_pw);
await console.log("로그인 정보 삽입 완료")
await page.click('#container > form > p.submit > input');
await page.waitFor(1000);
await page.goto('https://everytime.kr/lecture');
await page.evaluate((lec) => {
document.querySelector("input[name=keyword]").value = lec;
}, lecture);
await page.click('#container > form > input.submit');
await page.waitFor(1000);
let tempclass = await page.evaluate((sel) => {
return Array.from(document.getElementsByClassName(sel)).map(node => node.href);
}, 'lecture');
console.log(tempclass)
for (var i in tempclass) {
console.log(tempclass[i]);
await page.goto(tempclass[i]);
await page.waitFor(1000);
await page.waitForSelector('#container > div.side.head > h2');
const lecturename = await page.evaluate(() => {
const anchors1 = Array.from(document.querySelectorAll('#container > div.side.head > h2'));
return anchors1.map(anchor1 => anchor1.textContent);
});
await page.waitForSelector('#container > div.side.head > p:nth-child(3) > span');
const proname = await page.evaluate(() => {
const anchors2 = Array.from(document.querySelectorAll('#container > div.side.head > p:nth-child(3) > span'));
return anchors2.map(anchor2 => anchor2.textContent);
});
await page.waitForSelector('#container > div.side.article > div.rating > div.rate > span > span.value');
const avg_rate = await page.evaluate(() => {
const anchors3 = Array.from(document.querySelectorAll('#container > div.side.article > div.rating > div.rate > span > span.value'));
return anchors3.map(anchor3 => anchor3.textContent);
});
let review = [];
if (await page.$('#container > div.side.article > div.articles > article > p.text') !== null){
await page.waitForSelector('#container > div.side.article > div.articles > article > p.text');
review = await page.evaluate(() => {
const anchors4 = Array.from(document.querySelectorAll('#container > div.side.article > div.articles > article > p.text'));
return anchors4.map(anchor4 => anchor4.textContent);
});
}
//콘솔에 출력한다.
console.log(lecturename.join('\n'));
console.log(proname.join('\n'));
console.log(avg_rate.join('\n'));
console.log(review);
}
await browser.close();
})();