-
Notifications
You must be signed in to change notification settings - Fork 0
/
scholars4DevSitemap.js
49 lines (34 loc) · 1.14 KB
/
scholars4DevSitemap.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
const puppeteerConfig = require("./puppeteerConfig");
const puppeteer = puppeteerConfig();
const searchScholars4DevSitemap = 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://www.scholars4dev.com/sitemap/`);
await page.waitForSelector("div[class=sitemap]");
const searchResults = await page.$$eval(".cat-item", (results) => {
let data = [];
results.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 = searchScholars4DevSitemap;