-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourseStatus.js
44 lines (34 loc) · 1007 Bytes
/
courseStatus.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
const puppeteer = require('puppeteer');
const debug = require('debug')('app: CourseStatus: 📚 ');
const { puppeteerConfig } = require('./config');
async function webScrape({ url, selector, xpath }) {
const browser = await puppeteer.launch(puppeteerConfig);
const page = await browser.newPage();
await page
.goto(url, {
waitUntil: 'domcontentloaded',
timeout: 0,
})
.then(() => debug('Page loaded!!'));
await page
.waitForSelector(selector)
.then(() => debug('selector appeared'))
.catch((err) => {
debug('Unable to fetch the value');
debug(err);
browser.close();
});
const [el] = await page.$x(xpath);
const txt = await el.getProperty('textContent');
const underlyingValue = await txt.jsonValue();
await browser.close();
return underlyingValue;
}
// webScrape(courses.Fall[0])
// .then(() => {
// debug('Perfectyl occured!');
// })
// .catch((err) => {
// debug(err);
// });
module.exports = webScrape;