-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscholars4DevPost.js
56 lines (42 loc) · 1.4 KB
/
scholars4DevPost.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
const puppeteerConfig = require("./puppeteerConfig");
const puppeteer = puppeteerConfig();
const searchScholars4DevPost = 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("div[class=singlepost]", (result) => {
let data = [];
const title = result.querySelector("div[class='post clearfix'] > h1")
.innerText;
let date = result.querySelector(
"div[class='post clearfix'] > p[class=postinfo]"
).innerText;
const type = result
.querySelectorAll(
"div[class='entry clearfix'] > div[class=post_column_1]"
)[0]
.querySelector("p").innerText;
const details = result.querySelector("div[class='entry clearfix']")
.innerHTML;
date = date.replace(" |", "");
data.push({ title, date, type, details });
return data;
});
await browser.close();
return searchResults;
};
module.exports = searchScholars4DevPost;