Last active
March 21, 2020 16:06
-
-
Save DZuz14/3d5e01d241314550e898685329b8b0d5 to your computer and use it in GitHub Desktop.
Web Scraping With Node.js & Puppeteer
This file contains hidden or 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'); | |
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