Created
July 1, 2021 18:10
-
-
Save ulfandersson/a4e08e152bb4b83aec4af9437e490068 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
/** | |
* Ladda ner aktieinnehav från nordnet. Copy-paste till terminal och kör! | |
*/ | |
// (Use var instead of const to be able to copy-paste to console multiple times) | |
// The data is not a table, but row-based flexbox-divs. | |
var data = Array.from(document.querySelector("#pageAccountStocksTable").children, | |
rowDiv => rowDiv.innerText | |
// Remove Köp Sälj buttons | |
.replace("KöpSälj\n", "") | |
// Luckily we get a newline between each cell, replace with ; to create CSV columns | |
.replaceAll("\n", ";") | |
// Don't use comma in numbers | |
.replaceAll(",", ".") | |
// Replace − with a normal minus | |
.replaceAll("−", "-") | |
// Remove all spacing in the numbers | |
.replace(/(\d|-+)\s(\d+)/g, "$1$2")) | |
// Skip the last line "Totalt" | |
.slice(0, -1) | |
// Join to rows | |
.join("\n"); | |
// Create a link with the whole document in it | |
var pom = document.createElement('a'); | |
pom.setAttribute('href', 'data:text/x-csv;charset=utf-8,' + encodeURIComponent(data)); | |
// Both Depånummer and Bankkontonummer exists with a class that includes "DepotNumber", the first should be the correct one | |
var accountNumber = document.querySelectorAll("span[class*=DepotNumbers]").item(0).innerText.replace("Depånummer ", ""); | |
// This attribute will be the filename | |
pom.setAttribute('download', `nordnet-${accountNumber}.csv`); | |
// Click the link to start the download | |
pom.click(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment