-
Notifications
You must be signed in to change notification settings - Fork 0
/
indbeasiswa.js
58 lines (41 loc) · 1.38 KB
/
indbeasiswa.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
const puppeteerConfig = require("./puppeteerConfig");
const puppeteer = puppeteerConfig();
const searchIndbeasiswa = async (pageNumber) => {
const browser = await puppeteer.launch({
headless: true,
args: ["--no-sandbox"],
});
const page = await browser.newPage();
//turns request interceptor on
await page.setRequestInterception(true);
//if the page makes a request to a resource type of image or stylesheet then abort that request
page.on("request", (request) => {
if (
request.resourceType() === "image" ||
request.resourceType() === "stylesheet"
)
request.abort();
else request.continue();
});
await page.goto(`https://indbeasiswa.com/page/${pageNumber}?s=beasiswa)`);
await page.waitForSelector("div[class=content-inner]");
const searchResults = await page.$$eval(
"div[class=post-right]",
(results) => {
let data = [];
results.forEach((result) => {
const title = result.querySelector("h2 > a").innerText;
const url = result.querySelector("h2 > a").href;
let details = result.querySelector(
"div[class=post-content] > div[class=entry-content]"
).innerText;
details = details.replace("- ", "");
data.push({ title, url, details });
});
return data;
}
);
await browser.close();
return searchResults;
};
module.exports = searchIndbeasiswa;