Skip to content

Instantly share code, notes, and snippets.

@safinahmed
Last active June 9, 2025 06:49
Show Gist options
  • Select an option

  • Save safinahmed/e2f29057d5331d6a8309f3432c4a09fc to your computer and use it in GitHub Desktop.

Select an option

Save safinahmed/e2f29057d5331d6a8309f3432c4a09fc to your computer and use it in GitHub Desktop.
Javascript to export TradingView Screener as CSV

TradingView Screener Exporter

Simple JS to export the result of a TradingView Screener (https://www.tradingview.com/screener/) to CSV

Provides 2 methods to download the whole table wth headers, or only the tickers without headers

Run the whole script on the console, then run method exportTable to export everything, or exportTickers for tickers only

function exportTable() {
var data = [];
var rows = document.querySelectorAll("table tr");
for (var i = 0; i < rows.length; i++) {
if(i == 1)
continue;
var row = [], cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++) {
row.push(cols[j].innerText.replaceAll('\n',' ').replaceAll(",","").replaceAll("USD",""));
}
data.push(row.join(","));
}
downloadCSVFile(data.join("\n"), "table.csv");
}
function exportTickers() {
var data = [];
var rows = document.querySelectorAll("table tr");
for (var i = 2; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll("td, th");
row.push(cols[0].querySelector("a").innerText);
data.push(row.join(","));
}
downloadCSVFile(data.join("\n"), "tickers.csv");
}
function downloadCSVFile(csv, filename) {
var csv_file, download_link;
csv_file = new Blob([csv], {type: "text/csv"});
download_link = document.createElement("a");
download_link.download = filename;
download_link.href = window.URL.createObjectURL(csv_file);
download_link.style.display = "none";
document.body.appendChild(download_link);
download_link.click();
}
@wencio
Copy link

wencio commented Jun 1, 2023

thanks
safinahmed .. question can we use the code to export the trades from paper trading to a csv?

@Dileesha-abilash
Copy link

thanks, you saved my money 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment