Skip to content

Instantly share code, notes, and snippets.

@DZuz14
Last active March 21, 2020 16:06
Show Gist options
  • Save DZuz14/3d5e01d241314550e898685329b8b0d5 to your computer and use it in GitHub Desktop.
Save DZuz14/3d5e01d241314550e898685329b8b0d5 to your computer and use it in GitHub Desktop.
Web Scraping With Node.js & Puppeteer
const puppeteer = require('puppeteer');
async function main() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://some-website.com');
// Full access to the browser environment.
await page.evaluate(() => {
const links = document.querySelectorAll('ul.sidebar li a');
console.log(links)
});
// Take a screenshot
await page.screenshot({path: 'example.png'});
// Create a PDF
await page.pdf({ path: 'example.pdf', format: 'A4' });
await browser.close()
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment