Skip to content

Instantly share code, notes, and snippets.

@johnmurch
Created March 24, 2020 23:55
Show Gist options
  • Save johnmurch/f4cc6cb0729d67f7c2bf61efc5f110eb to your computer and use it in GitHub Desktop.
Save johnmurch/f4cc6cb0729d67f7c2bf61efc5f110eb to your computer and use it in GitHub Desktop.
Puppeteer Heading tags - Snippet
const h1s = await page.evaluate(
() => [...document.querySelectorAll('h1')].map(elem => elem.innerText.trim()))
const h2s = await page.evaluate(
() => [...document.querySelectorAll('h2')].map(elem => elem.innerText.trim()))
const h3s = await page.evaluate(
() => [...document.querySelectorAll('h3')].map(elem => elem.innerText.trim()))
const h4s = await page.evaluate(
() => [...document.querySelectorAll('h4')].map(elem => elem.innerText.trim()))
const h5s = await page.evaluate(
() => [...document.querySelectorAll('h5')].map(elem => elem.innerText.trim()))
const h6s = await page.evaluate(
() => [...document.querySelectorAll('h6')].map(elem => elem.innerText.trim()))
console.log('h1s', h1s)
console.log('h2s', h2s)
console.log('h3s', h3s)
console.log('h4s', h4s)
console.log('h5s', h5s)
console.log('h6s', h6s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment