-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawling_new.js
122 lines (101 loc) · 3.49 KB
/
crawling_new.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Node.js Puppeteer, Crawler coding #News
* 쇼더코딩 Show the coding
* https://youtu.be/LENypLTZxNg
*/
const puppeteer = require('puppeteer');
const cheerio = require('cheerio');
const test = ($) => {
const objs = [];
$('.DWs4Q').each((idx, el) => {
objs.push({
'title': $(el).find('.place_bluelink ').text(),
'review': $(el).find('.wt0BA').text()
});
});
return objs;
};
const site = {
'name': '검색',
'url': 'https://search.naver.com/search.naver?where=nexearch&sm=tab_jum&query=',
'filter': ($) => test($),
};
(async () => {
const keyword = '건대피부과';
const browser = await puppeteer.launch();
const [page] = await browser.pages();
await page.goto(site.url + keyword, { 'waitUntil': 'networkidle0' });
const rst = site.filter(cheerio.load(await page.content()));
console.log('-----------------------------------------------');
console.log(site.name);
console.log(rst);
console.log('-----------------------------------------------');
// for await (const site of targets) {
// await page.goto(site.url + keyword, { 'waitUntil': 'networkidle0' });
// const rst = site.filter(cheerio.load(await page.content()));
// console.log('-----------------------------------------------');
// console.log(site.name);
// console.log(rst);
// console.log('-----------------------------------------------');
// }
await browser.close();
})();
// const naverNewsFilter = ($) => {
// const objs = [];
// $('.press_edit_news_item').each((idx, el) => {
// objs.push({
// 'title': $(el).find('.press_edit_news_title').text(),
// 'link': $(el).find('.press_edit_news_link').attr('href'),
// });
// });
// return objs;
// };
// const daumNewsFilter = ($) => {
// const objs = [];
// $('#mArticle > div.box_etc > ul > li').each((idx, el) => {
// objs.push({
// 'title': $(el).find('.link_txt').text().split('\n')[0],
// 'link': $(el).find('.link_txt').attr('href'),
// });
// });
// return objs;
// }
// const naverHaniInter = {
// 'name': '한겨레 - 세계',
// 'url': 'https://media.naver.com/press/028?sid=104',
// 'filter': ($) => naverNewsFilter($),
// };
// const naverHaniIt = {
// 'name': '한겨레 - IT',
// 'url': 'https://media.naver.com/press/028?sid=105',
// 'filter': ($) => naverNewsFilter($),
// };
// const naverHaniEco = {
// 'name': '한겨레 - 경제',
// 'url': 'https://media.naver.com/press/028?sid=101',
// 'filter': ($) => naverNewsFilter($),
// };
// const daumNewEco = {
// 'name': '다음 - 경제',
// 'url': 'https://news.daum.net/breakingnews/economic',
// 'filter': ($) => daumNewsFilter($),
// };
// (async () => {
// const targets = [
// naverHaniInter,
// naverHaniIt,
// naverHaniEco,
// daumNewEco
// ];
// const browser = await puppeteer.launch();
// const [page] = await browser.pages();
// for await (const site of targets) {
// await page.goto(site.url, { 'waitUntil': 'networkidle0' });
// const rst = site.filter(cheerio.load(await page.content()));
// console.log('-----------------------------------------------');
// console.log(site.name);
// console.log(rst);
// console.log('-----------------------------------------------');
// }
// await browser.close();
// })();