-
Notifications
You must be signed in to change notification settings - Fork 1
/
scrape.js
37 lines (29 loc) · 1.11 KB
/
scrape.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
const puppeteer = require('puppeteer');
let scrape = async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://my.sa.ucsb.edu/gold/Login.aspx', {waitUntil:'networkidle2'});
await page.focus('#pageContent_userNameText');
await page.keyboard.type('priscilla_lee');
await page.focus('#pageContent_passwordText');
await page.keyboard.type('25754SbJ');
await page.click('#pageContent_loginButton');
await page.waitForNavigation();
await page.click('#Li0 > a');
await page.waitFor(1000);
const result = await page.evaluate(() => {
let title = document.querySelector('#ctl00_pageContent_CourseList_ctl00_CourseHeadingLabel').innerText;
let day = document.querySelector('.col-lg-days.col-lg-push-0.col-sm-2.col-sm-pull-0.col-xs-6.col-xs-pull-6').innerText;
let time = document.querySelector('.col-lg-time.col-md-time.col-sm-4.col-xs-6').innerText;
return {
title,
day,
time
}
});
browser.close();
return result;
};
scrape().then((value) => {
console.log(value); // Success!
});