**The Website: **
littlewargame.com/test
**Idea: **
Get the stats of the laddergames of my profile as csv.
**Problem: **
The data I get only shows the data of the first page. But I want the entirety of the games data.
Current halfworking Solution:
- Step: “Inspect” via Google Chrome to open devtools
- Paste Code into “Console”
- Change
playerLadderResultsToCSV('DrEbs16')accordingly
Here is a video of how it currently works: https://drive.google.com/file/d/1JHiWIdBu6vydQ-iIN_VhjOoxMI4y2mQw/view?usp=sharing
The Code:
playerLadderResultsToCSV('DrEbs16');
function playerLadderResultsToCSV(playerNameToScrapeFor) {
const playersWindowTextArea = document.getElementById('playersWindowTextArea')
const player = Array.from(playersWindowTextArea.childNodes).find(childNode => {
const playerName = childNode.querySelector('a.playerNameInList').innerText
console.log('playerName', playerName);
return playerName === playerNameToScrapeFor;
});
player.querySelector('a.playerNameInList').click();
// wait 2 seconds
setTimeout(() => {
openLadderGamesProfile();
}, 2000); // milliseconds to wait for profile to open (just to be safe)
}
function openLadderGamesProfile() {
const ladderGamesBtn = Array.from(document.getElementById('riderDiv').childNodes).find(node => node.innerText === 'Laddergames')
ladderGamesBtn.click();
setTimeout(() => {
const csvData = extractLadderGamesData();
console.log(csvData)
}, 2000); // milliseconds to wait for ladder contents to fill (just to be safe)
}
function extractLadderGamesData(trElem) {
const trs = document.querySelectorAll('#addScrollableSubDivTextArea table tr')
return Array.from(trs).map(trElem => {
const tds = trElem.childNodes;
const firstPlayer = tds[0].innerText.trim();
const secondPlayer = tds[2].innerText.trim()
const gameResult = tds[3].innerText.trim();
const datePlayed = tds[4].innerText.trim();
const mapName = tds[5].innerText.trim();
let csvRow = `${firstPlayer},${secondPlayer},${gameResult},${datePlayed},${mapName}`;
return csvRow;
}).join('n').trim();
}

