Created
August 23, 2017 21:29
-
-
Save dremendes/b01ee2af936c9b875767dcd5b7aa8228 to your computer and use it in GitHub Desktop.
Facebook video download with puppeteer example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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