Created
April 23, 2024 15:26
-
-
Save bitmvr/805ecfe4399434c240c8a920f92d06be to your computer and use it in GitHub Desktop.
Pokemon Scraper
This file contains hidden or 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
/* 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