Skip to content

Instantly share code, notes, and snippets.

@rwinscot
Created May 17, 2018 13:59
Show Gist options
  • Save rwinscot/68133ca7f09a200ab266dabb3953e9a5 to your computer and use it in GitHub Desktop.
Save rwinscot/68133ca7f09a200ab266dabb3953e9a5 to your computer and use it in GitHub Desktop.
Google Chrome Headless with Puppeteer: Loading Website Extract Quickly
// 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