-
Notifications
You must be signed in to change notification settings - Fork 0
/
indbeasiswaPost.js
46 lines (33 loc) · 1.07 KB
/
indbeasiswaPost.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
const puppeteerConfig = require("./puppeteerConfig");
const puppeteer = puppeteerConfig();
const searchIndbeasiswaPost = async (url) => {
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(url);
const searchResults = await page.$eval("article", (result) => {
let data = [];
const title = result.querySelector("div > h1").innerText;
let details = result.querySelector(
"div[class=post-content] > div[class=entry-content]"
).innerHTML;
data.push({ title, details });
return data;
});
await browser.close();
return searchResults;
};
module.exports = searchIndbeasiswaPost;