Created
July 29, 2020 17:49
-
-
Save kurtroberts/7a3fcc807403e6ef381dc78e1cb9ec63 to your computer and use it in GitHub Desktop.
Fun with browser automation
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'); | |
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