Skip to content

Instantly share code, notes, and snippets.

@jackfranklin
Created February 8, 2021 16:54
Show Gist options
  • Save jackfranklin/06bed136fdb22419cb7a8a9a4d4ef32f to your computer and use it in GitHub Desktop.
Save jackfranklin/06bed136fdb22419cb7a8a9a4d4ef32f to your computer and use it in GitHub Desktop.
const puppeteer = require('puppeteer')
async function run() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
const stuff = await page.$('div')
if (!stuff) {
throw new Error('no stuff')
}
const foo = await stuff.evaluate((elem) => {
const x = elem.getAttribute('data-x') || '0'
return window.parseInt(x);
});
console.log(foo)
}
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment