Znote (recipes)
  Get Znote  

Web scraping: Facebook login

Performs a Facebook authentication by web scraping


Facebook login

npm package installation

npm i -S playwright
const USERNAME="XXX@gmail.com";
const { chromium } = require('playwright');

//const browser = await chromium.launch();
const browser = await chromium.launch({
    headless: false,
    args: ['--window-size=1280,720'],

const page = await browser.newPage();

// login
await page.goto('https://www.facebook.com/');
await sleep2(3000);
await page.locator('role=button[name="Uniquement autoriser les cookies essentiels"]').click();
await page.locator('//*[@id="email"]').fill(USERNAME);
await page.locator('//*[@id="pass"]').fill(PASSWORD);
await page.locator('button[name="login"]').click();

await sleep2(15000); // waiting ajax query//await page.waitFor(2000);
// go to form
//await page.goto("https://app.getform.io/forms/18848");
//await sleep2(3000); // waiting ajax query
// get nbr of pages
//const footer = await page.$('//*[@id="formScroll"]/div/div/div/div/div[2]/table/div/div/div');
//const nbrPages = await footer.evaluate(element => element.children.length);

Related recipes