Skip to content

Instantly share code, notes, and snippets.

@Virksaabnavjot
Last active November 17, 2020 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Virksaabnavjot/5928bd4fd532dc7f4002c84a38610a86 to your computer and use it in GitHub Desktop.
Save Virksaabnavjot/5928bd4fd532dc7f4002c84a38610a86 to your computer and use it in GitHub Desktop.
Javascript Solution to Export Dividend Data from Trading212 (in JSON) - Trading212 Reporting
//let length = document.getElementsByClassName('r3p0r7s000-subheading');
let length = 3; //you can change me around
let data = {dividends : [] };
for (i=0; i <= length; i++){
let companyName = document.getElementsByClassName('r3p0r7s000-subheading')[i].innerHTML;
let dividendAmount = document.getElementsByClassName('r3p0r7s000-main-info')[i].innerHTML;
var dividend = {
"companyName": companyName,
"dividendAmount": dividendAmount
}
data.dividends.push(dividend);
}
console.log(JSON.stringify(data));
@Virksaabnavjot
Copy link
Author

Virksaabnavjot commented Nov 17, 2020

Demo: https://codepen.io/virksaabnavjot/pen/zYBbJRa?editors=1010

Steps:
Step 1- Open a New Tab in Chrome > Right Click and Select Inspect
Step 2- Now Open your Trading212 Account in this Tab and Open the Dividends section as highlighted in screenshot below (select dates as required)
Solution in Action on Trading212
Screenshot 2020-11-17 at 01 22 41

Step 3- On the Inspect Tool > Go to Console > Paste and Above Code and click enter to run (you can adjust the length value, still working on making that dynamic)
Sample Output - in JSON Format
{"dividends":[{"companyName":"Realty Income","dividendAmount":"+$0.14"},{"companyName":"Nucor","dividendAmount":"+$0.01"},{"companyName":"American Express","dividendAmount":"+$0.08"},{"companyName":"AGNC Investment","dividendAmount":"+$0.01"}]}

Step 4- Convert JSON Data to Table (then you can simply copy and paste it in Excel or Google Sheets)
Tool to convert JSON to a Table: http://json2table.com/
Screenshot 2020-11-17 at 01 21 15

Screenshot 2020-11-17 at 00 25 18

Please leave comments for any questions or feedback.

Thanks
Nav
Visit my blog at: https://mrvirk.com to read about some awesome javascript solutions and investing

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