-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (28 loc) · 1.13 KB
/
app.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
import puppeteer from 'puppeteer';
import fs from 'fs';
async function main() {
const browser = await puppeteer.launch();
const page = await browser.newPage()
await page.goto('https://www.traversymedia.com/')
//*for capture full page image
// await page.screenshot({path: './assets/images/test.png', fullPage: 'true'})
//*for get pdf file
// await page.pdf({path: './assets/files/test.pdf', format: 'A4'})
//*get html content
// const html = await page.content()
//*get documents
// const title = await page.evaluate(()=> document.body.innerText)
//*get all link in page
// const links = await page.evaluate(()=> Array.from(document.querySelectorAll('a'), (e)=> e.href))
//*get all courses from this site
const courses = await page.evaluate(()=> Array.from(document.querySelectorAll('.cscourse-grid .card'), (e)=> ({
title: e.querySelector('.card-body h3').innerHTML
})))
console.log(courses);
fs.writeFile('test.json', JSON.stringify(courses), (err)=> {
if(err) throw err;
console.log('file saved');
})
await browser.close()
}
main();