Skip to content

Instantly share code, notes, and snippets.

@tnolet
Created February 23, 2018 18:17
Show Gist options
  • Save tnolet/a767a5a1eea3ed7b5dcf7c8d3f522811 to your computer and use it in GitHub Desktop.
Save tnolet/a767a5a1eea3ed7b5dcf7c8d3f522811 to your computer and use it in GitHub Desktop.
Puppeteer search youtube
const puppeteer = require('puppeteer')
const screenshot = 'youtube_fm_dreams_video.png'
try {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('https://youtube.com')
await page.type('#search', 'Fleetwood Mac Dreams')
await page.click('button#search-icon-legacy')
await page.waitForSelector('ytd-thumbnail.ytd-video-renderer')
await page.screenshot({
path: 'youtube_fm_dreams_list.png'
})
const videos = await page.$$('ytd-thumbnail.ytd-video-renderer')
await videos[2].click()
await page.waitForSelector('.html5-video-container')
await page.waitFor(5000)
await page.screenshot({
path: screenshot
})
await browser.close()
console.log('See screenshot: ' + screenshot)
} catch (err) {
console.error(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment