Skip to content

Instantly share code, notes, and snippets.

@vsemozhetbyt
Created March 23, 2019 16:10
Show Gist options
  • Save vsemozhetbyt/bff88b6b15e5bb2571ee8e8d9001a84a to your computer and use it in GitHub Desktop.
Save vsemozhetbyt/bff88b6b15e5bb2571ee8e8d9001a84a to your computer and use it in GitHub Desktop.

Revisions

  1. vsemozhetbyt created this gist Mar 23, 2019.
    26 changes: 26 additions & 0 deletions test-puppeteer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    'use strict';

    const puppeteer = require('puppeteer');

    (async function main() {
    try {
    const browser = await puppeteer.launch();
    const [page] = await browser.pages();

    await page.goto('https://example.org/');

    const data = await page.evaluate(() => {
    const hrefs = Array.from(
    document.querySelectorAll('a[href]'),
    ({ href }) => href
    );
    return Array.from(new Set(hrefs));
    });

    console.log(data);

    await browser.close();
    } catch (err) {
    console.error(err);
    }
    })();