Skip to content

Instantly share code, notes, and snippets.

@jlhernando
Created January 11, 2024 10:49
Show Gist options
  • Save jlhernando/81d92f444575421eeb9aadb8d464484c to your computer and use it in GitHub Desktop.
Save jlhernando/81d92f444575421eeb9aadb8d464484c to your computer and use it in GitHub Desktop.
Scraping Coverage Numbers NodeJS Playwright
// Scrape top coverage numbers
const topNum = await page
.evaluate(
([url, selector]) => {
const raw = Array.from(document.querySelectorAll(selector), (el) => Number(el.title.replace(/,/g, '')));
const lastUpdated = document.querySelector('div[jslog]').childNodes[1].textContent.trim();
const report = {
property: url,
error: 0,
warning: 0,
valid: raw[1],
excluded: raw[0],
lastUpdated,
};
return report;
},
[property, reportSelector]
)
.catch((e) => console.log(e));
console.log(property, topNum);
results.push(topNum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment