Skip to content

Instantly share code, notes, and snippets.

@kurtroberts

kurtroberts/index.js

Created Jul 29, 2020
Embed
What would you like to do?
Fun with browser automation
const puppeteer = require('puppeteer');
async function getLink (url, xpathExpression) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
let link = await page.$eval(xpathExpression, anchor => { return anchor.href; });
await browser.close();
return link;
};
(async () => {
getLink('https://www.bluejeans.com/downloads', 'a[aria-label="Download BlueJeans for Mac"]').then(o => console.log(o));
getLink('https://www.barebones.com/products/bbedit/download.html', 'table:first-of-type a.button').then(o => console.log(o));
getLink('https://cyberduck.io/download/','a[href^="https://update.cyberduck.io/Cyberduck"]').then(o => console.log(o));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.