-
Notifications
You must be signed in to change notification settings - Fork 1
/
crawler.js
53 lines (40 loc) · 1.63 KB
/
crawler.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
const puppeteer = require('puppeteer');
async function scrapeDynamicContent(url) {
const browser = await puppeteer.launch({
headless: false,
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
await page.setBypassCSP(true);
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36');
await page.goto(url, { waitUntil: 'networkidle2' });
await page.waitForSelector('#sidoCd');
await page.select('#sidoCd', 11);// 서울 특별시
await page.waitForTimeout(1000);
await page.evaluate(() => sggList());
await page.waitForSelector('#sggCd');
await page.select('#sggCd', '11200');
await page.waitForTimeout(1000);
await page.waitForSelector('input.sch-btn');
await page.click('input.sch-btn');
await page.waitForSelector('table.table05', { timeout: 60000 });
const results = await page.evaluate(() => {
const rows = Array.from(document.querySelectorAll('table.table05 tbody tr'));
return rows.map(row => {
const columns = row.querySelectorAll('td');
return {
병의원명: columns[0].innerText.trim(),
전화번호: columns[1].innerText.trim(),
주소: columns[2].innerText.trim()
};
});
});
await browser.close();
return results;
}
async function main() {
const url = 'https://nip.kdca.go.kr/irhp/mngm/goMedicalCenterList.do';
const dynamicContent = await scrapeDynamicContent(url);
console.log(dynamicContent);
}
main();