Skip to content

Instantly share code, notes, and snippets.

@hcho3
Created September 14, 2025 06:39
Show Gist options
  • Select an option

  • Save hcho3/a2fdbfcca2bfdd9cc0f6d1cdebe9387f to your computer and use it in GitHub Desktop.

Select an option

Save hcho3/a2fdbfcca2bfdd9cc0f6d1cdebe9387f to your computer and use it in GitHub Desktop.
Userscript for exporting credit card transactions from Amazon.com
// ==UserScript==
// @name Amazon transactions exporter
// @namespace https://hyunsu-cho.io/
// @version 2025-09-13
// @description Compile list of credit card transactions from Amazon.com
// @author Hyunsu Cho
// @match https://www.amazon.com/cpe/yourpayments/transactions
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
// @grant none
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @require https://raw.githubusercontent.com/eligrey/FileSaver.js/master/dist/FileSaver.min.js
// ==/UserScript==
function parse_transaction(transaction, date) {
let payment_method = transaction.children("div").eq(0).children("div").eq(0).find("span").text();
let amount = transaction.children("div").eq(0).children("div").eq(1).find("span").text();
let order = transaction.children("div").eq(1).find("a.a-link-normal");
return {
date: date,
payment_method: payment_method,
amount: amount,
order_no: order.text(),
order_url: order.attr("href")
};
}
function parse_page() {
var transactions = new Array();
var elements = $('div.apx-transaction-date-container').add('div.apx-transactions-line-item-component-container');
var last_date = "";
elements.each(function() {
if ($(this).hasClass("apx-transaction-date-container")) {
last_date = $(this).find("span").text();
} else if ($(this).hasClass("apx-transactions-line-item-component-container")) {
transactions.push(parse_transaction($(this), last_date));
}
});
return transactions
}
$(document).ready(function() {
$('body').append('<input type="button" value="Fetch transactions" id="CP">')
$("#CP").css("position", "fixed").css("bottom", 0).css("right", 0);
$('#CP').click(function(){
let transactions = parse_page();
let file_content = new Blob([JSON.stringify(transactions)], { type: "application/json;charset=utf-8" });
saveAs(file_content, `${crypto.randomUUID()}.json`);
});
});
@hcho3
Copy link
Author

hcho3 commented Sep 14, 2025

How to use:

  1. Install Tampermonkey, Greasemonkey or other browser extension to enable user scripts.
  2. Visit https://www.amazon.com/cpe/yourpayments/transactions, which will list all credit card transactions from Amazon.com.
  3. Click on the "Fetch transactions" button on the bottom right. You will see a prompt window to download a JSON file, which will contain the credit card transactions that are displayed on the page.
Screenshot 2025-09-13 234413
  1. Now navigate to the next page and repeat Step 3, to fetch the next set of transactions. Repeat as necessary, to download all transactions you want.
  2. Collect the credit card transactions into a neat spreadsheet, by running the following Python script:
import json
import pathlib

import pandas as pd


def main():
    transactions = []
    for e in pathlib.Path(".").glob("*.json"):
        with open(e, "r") as f:
            transactions.extend(json.load(f))

    df = pd.DataFrame(transactions)
    df.to_csv("transactions_list.csv", index=False)


if __name__ == "__main__":
    main()

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