-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawler.js
39 lines (32 loc) · 1.21 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
const puppeteer = require("puppeteer");
const { puppeteerLaunchOptions } = require("./config");
const {
checkFreeTimes,
navigateToReservationPage,
wrapOpenDropDown,
wrapSelectOption,
} = require("./helpers");
const selectors = require("./selectors");
const crawl = async () => {
console.log("Going to start crawling ...");
const browser = await puppeteer.launch(puppeteerLaunchOptions);
const page = await browser.newPage();
const openDropDown = wrapOpenDropDown(page);
const selectOption = wrapSelectOption(page);
await navigateToReservationPage(page);
await openDropDown(selectors.dropdownButtonSelectors.CHOOSE_CATEGORY_BUTTON);
await selectOption(
selectors.categoryOptionSelectors.CATEGORY_RESIDENCE_PERMIT
);
await openDropDown(selectors.dropdownButtonSelectors.CHOOSE_SERVICE_BUTTON);
await selectOption(selectors.serviceOptionSelectors.WORK_SELECTOR);
await openDropDown(
selectors.dropdownButtonSelectors.CHOOSE_SERVICE_POINT_BUTTON
);
await selectOption(selectors.servicePointOptionSelectors.HELSINKI);
await page.click(selectors.otherSelectors.SEARCH_BUTTON);
await checkFreeTimes(page);
await page.waitFor(3000);
await browser.close();
};
module.exports = crawl;