Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Last active May 1, 2019 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhkeller/abc40a2c736063340f6b8ddc5301a1e3 to your computer and use it in GitHub Desktop.
Save mhkeller/abc40a2c736063340f6b8ddc5301a1e3 to your computer and use it in GitHub Desktop.
Basic puppeteer setup
const puppeteer = require('puppeteer');
main();
async function main () {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(`https://webpage.com`, { waitUntil: 'load' });
const mySelector = '.tk';
await page.waitForSelector(mySelector);
// Extract the results from the page.
const texts = await page.evaluate(sel => {
const els = Array.from(document.querySelectorAll(sel));
return els.map(el => {
const text = el.textContent.trim();
return text;
});
}, mySelector);
console.log(texts);
await browser.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment