Skip to content

Instantly share code, notes, and snippets.

@j127
Last active June 16, 2022 14:00
Show Gist options
  • Save j127/db76270d5d235a8f3dbb5d037c63b3c6 to your computer and use it in GitHub Desktop.
Save j127/db76270d5d235a8f3dbb5d037c63b3c6 to your computer and use it in GitHub Desktop.
Scrapes cat breed names from Wikipedia
// Scrapes cat breed names from https://en.wikipedia.org/wiki/List_of_cat_breeds
// Run it in the browser console on that page.
var table = document.querySelector("table");
var catNameArray =
[...table.querySelectorAll("th[scope='row']")]
.map((tr) => {
return tr
.innerText
.replace(/\[.+\]/, "") // removes everything in square brackets
.replace(/\n/g, " "); // removes all the newlines
});
// Join the array of cat names into an HTML string.
var output = catNameArray.join("<br>");
// Print the HTML output on the page.
document.body.innerHTML = output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment