Created
June 11, 2024 19:20
-
-
Save simeononsecurity/bb042df226b83d767343a2547be0aab5 to your computer and use it in GitHub Desktop.
This file contains 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
// This will click the "view more" button for you till it maxes out or doesn't load any more and then download the table as a csv for you. | |
(function() { | |
function tableToCSV() { | |
var csv = []; | |
var rows = document.querySelectorAll("#searchTable tr"); | |
// Loop through each row | |
for (var i = 0; i < rows.length; i++) { | |
var row = [], cols = rows[i].querySelectorAll("td, th"); | |
// Loop through each column | |
for (var j = 0; j < cols.length; j++) { | |
// Clean up the text and push it to the row array | |
row.push(cols[j].innerText.replace(/,/g, "")); | |
} | |
// Join each row's columns with a comma and push it to the csv array | |
csv.push(row.join(",")); | |
} | |
// Create a CSV string from the array | |
var csvString = csv.join("\n"); | |
// Create a blob from the CSV string | |
var blob = new Blob([csvString], { type: 'text/csv' }); | |
// Create a link element to initiate the download | |
var link = document.createElement("a"); | |
link.href = URL.createObjectURL(blob); | |
link.download = "table.csv"; | |
// Append the link, click it, and then remove it | |
document.body.appendChild(link); | |
link.click(); | |
document.body.removeChild(link); | |
} | |
function clickLoadMoreButton(callback) { | |
var loadMoreButton = document.getElementById("fetchNext"); | |
var totalRecords = parseInt(document.getElementById("ofTotal").innerText); | |
var loadedRecords = parseInt(document.getElementById("pageend").value); | |
if (loadedRecords < totalRecords) { | |
loadMoreButton.click(); | |
setTimeout(function() { | |
clickLoadMoreButton(callback); | |
}, 2000); // Adjust the timeout duration if necessary | |
} else { | |
callback(); | |
} | |
} | |
// Start the process | |
clickLoadMoreButton(tableToCSV); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment