Hello
Last active
September 7, 2020 06:53
-
-
Save oskarhane/25b96725f7742f6ff67d5f43441321fc to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
const puppeteer = require("puppeteer"); | |
const inArgs = process.argv.slice(2); | |
if (inArgs.length !== 1) { | |
console.log("Error, wrong usage."); | |
console.log("Usage: npx scrape-neo4j-browser-version <url-to-browser>"); | |
process.exit(1); | |
} | |
const url = inArgs.pop(); | |
(async () => { | |
try { | |
const browser = await puppeteer.launch({ | |
headless: true, | |
args: ['--no-sandbox'] | |
}); | |
const page = await browser.newPage(); | |
await page.goto(url); | |
await page.click('button[name="About"]'); | |
const target = await page.$$("div[id='db-about']"); | |
const text = await page.evaluate((el) => el.innerText, target[0]); | |
const versionMatch = text.match(/Neo4j Browser version: (\d+\.\d+\.\d+)/i); | |
const version = versionMatch && versionMatch.length ? versionMatch[1] : null; | |
if (!version) { | |
throw new Error(`No Neo4j Browser version found on url: ${url}`); | |
} | |
await browser.close(); | |
console.log(JSON.stringify({ version })); | |
process.exit(0); | |
} catch (e) { | |
if (typeof browser !== "undefined") { | |
await browser.close(); | |
} | |
console.error(e); | |
process.exit(1); | |
} | |
})(); |
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
{ | |
"name": "scrape-neo4j-browser-version", | |
"version": "1.0.0", | |
"description": "", | |
"bin": "./index.js", | |
"keywords": [], | |
"author": "Oskar Hane", | |
"dependencies": { | |
"puppeteer": "^5.2.1" | |
}, | |
"engines": { | |
"node": "13" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment