Last active
May 1, 2019 14:03
-
-
Save mhkeller/abc40a2c736063340f6b8ddc5301a1e3 to your computer and use it in GitHub Desktop.
Basic puppeteer setup
This file contains 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
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