-
Notifications
You must be signed in to change notification settings - Fork 0
/
indbeasiswaSitemap.js
53 lines (38 loc) · 1.23 KB
/
indbeasiswaSitemap.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 puppeteerConfig = require("./puppeteerConfig");
const puppeteer = puppeteerConfig();
const searchIndbeasiswaSitemap = async () => {
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 thatrequest
page.on("request", (request) => {
if (
request.resourceType() === "image" ||
request.resourceType() === "stylesheet"
)
request.abort();
else request.continue();
});
await page.goto("https://indbeasiswa.com/sitemap");
await page.waitForSelector("article");
const searchResults = await page.$eval("article", (results) => {
let data = [];
results
.querySelectorAll("div")[1]
.querySelectorAll("ul")[1]
.querySelectorAll("li")
.forEach((result) => {
const title = result.querySelector("a").innerText;
const url = result.querySelector("a").href;
data.push({ title, url });
});
return data;
});
await browser.close();
return searchResults;
};
module.exports = searchIndbeasiswaSitemap;