Created
May 17, 2018 13:59
-
-
Save rwinscot/68133ca7f09a200ab266dabb3953e9a5 to your computer and use it in GitHub Desktop.
Google Chrome Headless with Puppeteer: Loading Website Extract Quickly
This file contains hidden or 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
// NodeJS v8.11.1 | |
// Puppeteer v1.4.0 | |
// https://github.com/GoogleChrome/puppeteer/tree/v1.4.0 | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.setRequestInterception(true); | |
page.on('request', (request) => { | |
// trick here... is to ignore everything but the document | |
if (request.resourceType() !== 'document') { | |
request.abort(); | |
} else { | |
request.continue(); | |
} | |
}); | |
await page.goto('http://www.your-website-here.com'); | |
const title = await page.$eval('title', el => el.textContent); | |
const description = await page.$eval('meta[name="description"]', el => el.getAttribute("content")); | |
await browser.close(); | |
console.log(title); | |
console.log(description); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment