Skip to content

Instantly share code, notes, and snippets.

@bitmvr
Created April 23, 2024 15:26
Show Gist options
  • Save bitmvr/805ecfe4399434c240c8a920f92d06be to your computer and use it in GitHub Desktop.
Save bitmvr/805ecfe4399434c240c8a920f92d06be to your computer and use it in GitHub Desktop.
Pokemon Scraper
/* The follwing Javascript is to be used inside a browser's console to extract
data from the first three columns of the table. The website this code is designed
for is: https://www.serebii.net/pokemon/gen6pokemon.shtml
*/
var tableRows = document.querySelectorAll('.dextable tr');
var csvContent = '';
tableRows.forEach(function(row) {
var rowData = [];
var cells = row.querySelectorAll('td.fooinfo:nth-child(-n+3)');
if(cells.length > 0) { // Check if any cells with class 'fooinfo' are present
cells.forEach(function(cell) {
if (cell.textContent.trim() === "") {
var imgSrc = cell.querySelector('img').getAttribute('src');
var fullSrc = `=IMAGE("https://www.serebii.net${imgSrc}", 1)`
rowData.push(fullSrc.trim());
} else {
rowData.push(cell.textContent.trim());
}
});
csvContent += rowData.join('|') + '\n';
}
});
console.log(csvContent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment