33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
|
#!/usr/bin/env node
|
||
|
const puppeteer = require('puppeteer');
|
||
|
const aChecker = require("accessibility-checker");
|
||
|
const uuid = require("uuid");
|
||
|
|
||
|
async function scrapeLinks(url) {
|
||
|
const browser = await puppeteer.launch();
|
||
|
const page = await browser.newPage();
|
||
|
await page.goto(url, { 'timeout': 30 * 1000, 'waitUntil': 'load' });
|
||
|
const all_hrefs = await page.evaluate(() => Array.from(document.querySelectorAll('a[href]')).map(x => x.href));
|
||
|
const links_mess = all_hrefs.filter(x => x.startsWith('https://') || x.startsWith('http://')).map(x => x.split('#')[0]);
|
||
|
const links = Array.from(new Set(links_mess)).sort();
|
||
|
const element_count = await page.evaluate(() => document.querySelectorAll('*').length);
|
||
|
const uid = uuid.v4();
|
||
|
const compliance = await aChecker.getCompliance(page, uid);
|
||
|
const results = compliance.report.results;
|
||
|
await browser.close();
|
||
|
return {
|
||
|
element_count,
|
||
|
links,
|
||
|
results,
|
||
|
};
|
||
|
}
|
||
|
|
||
|
async function main() {
|
||
|
if (process.argv.length != 3) {
|
||
|
throw new Error('Requires exactly one argument');
|
||
|
}
|
||
|
console.log(JSON.stringify(await scrapeLinks(process.argv[2])));
|
||
|
}
|
||
|
|
||
|
main();
|