-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrainyQuote.js
46 lines (35 loc) · 1.29 KB
/
brainyQuote.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 { write } = require('fs');
const puppeteer = require('puppeteer');
const fs = require('fs');
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
// put link here - Make sure they are links for a specific person...
await page.goto('https://www.brainyquote.com/authors/justin-amash-quotes');
await page.waitForTimeout(500)
let writeArray = []
writeArray = await page.evaluate(() => {
let segment = {
"quote": "",
"author": ""
}
let returnArray = []
for (i = 1; i < document.querySelector("#quotesList").children.length; i++) {
segment = {
"quote": "",
"author": ""
}
try {
segment.quote = document.querySelector(`#quotesList >div:nth-child(${i})>div>a`).innerText
segment.author = document.querySelector(`#quotesList >div:nth-child(${i})>div>a:nth-child(3)`).innerText
} catch (err) {
console.log(err)
}
returnArray.push(segment)
}
return returnArray
})
console.log(writeArray)
fs.writeFileSync('brainyQuote.json', JSON.stringify(writeArray));
// await browser.close();
})();