DEV Community

loading...
Cover image for How to use Puppeteer to scrape  your MonBureauNumerique's timetable.

How to use Puppeteer to scrape your MonBureauNumerique's timetable.

Arnaud Lier
Junior French DevOps
Updated on ・1 min read
const puppeteer = require('puppeteer');

async function timetable() {
    const browser = await puppeteer.launch({
        headless: true,
        args: ['--no-sandbox']
    });
    const page = await browser.newPage();
    await page.setViewport({
        width: 1920,
        height: 1080
    });
    await page.goto('https://cas.monbureaunumerique.fr/login?service=https%3A%2F%2Fclg-schuman-volgelsheim.monbureaunumerique.fr%2Fsg.do%3FPROC%3DIDENTIFICATION_FRONT', {
        waitUntil: 'networkidle0'
    });
    await page.waitForSelector('.panel__body > .cas__wayf-form > div:nth-child(7) > .cas__wayf-idp > .form__label')
    await page.click('.panel__body > .cas__wayf-form > div:nth-child(7) > .cas__wayf-idp > .form__label')
    await page.click('#button-submit');
    await page.waitForNavigation({
        waitUntil: 'networkidle0'
    });
    await page.type('#username', '[USERNAME HERE]');
    await page.type('#password', '[PASSWORD HERE]');
    await Promise.all([
        page.click('#bouton_valider'),
        page.waitForNavigation({
            waitUntil: 'networkidle0'
        }),
    ]);
    await page.goto('https://clg-schuman-volgelsheim.monbureaunumerique.fr/sg.do?PROC=CDT&VUE=E');
    await page.screenshot({
        path: 'timetable.png',
        clip: {
            x: 394,
            y: 279,
            width: 1515,
            height: 583
        }
    })
    await browser.close();
}

timetable();
Enter fullscreen mode Exit fullscreen mode

This will save your timetable to a file named timetable.png
Enjoy!

Discussion (0)