Skip to content

Instantly share code, notes, and snippets.

@dremendes
Created August 23, 2017 21:29
Show Gist options
  • Save dremendes/b01ee2af936c9b875767dcd5b7aa8228 to your computer and use it in GitHub Desktop.
Save dremendes/b01ee2af936c9b875767dcd5b7aa8228 to your computer and use it in GitHub Desktop.
Facebook video download with puppeteer example
const puppeteer = require('puppeteer');
const { URL } = require('url');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const link = new URL('http://www.facebook.com/dcmjunior/videos/1794891250528272/');
if(["www.facebook.com",
"facebook.com",
"www.fb.com",
"fb.com",
"m.facebook.com",
"mobile.facebook.com"
].includes(link.host)){
await page.goto("http://m.facebook.com" +
link.href.substring(link.origin.length, link.href.length),
{waitUntil: 'networkidle'});
await page.click('#u_0_0 > div > div > div > div > div > i');
await page.waitForSelector('#mInlineVideoPlayer', {visible: true});
// Pega o link do video da página
const videoLink = await page.evaluate(() => {
return document.getElementById('mInlineVideoPlayer').src;
});
console.log(videoLink);
} else {
console.log('URL fornecida é inválida')
}
browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment