2026-01-09
For Bursa Malaysia (KLSE) and Singapore Exchange (SGX), we can scrape from some other websites websites like growbeansprout and klsescreener. This is how.
As of today, klsescreener still works for the Google Sheets scraper, albeit with an extra step that checks for presence of cookie. We can make it work by implementing a custom formula with Google App Script.
Step 1: At the top of your Google Sheets, click Extensions > App Script.
Step 2: Copy this script below, paste it in, save:
/**
* Get KLSE stock price
* @param {string} stockCode - Stock code (e.g., "5176")
* @return Current price
* @customfunction
*/
function KLSE(stockCode) {
var chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
var cookie = '';
for (var i = 0; i < 26; i++) {
cookie += chars.charAt(Math.floor(Math.random() * chars.length));
}
var response = UrlFetchApp.fetch(
'https://www.klsescreener.com/v2/stocks/view/' + stockCode + '/',
{
headers: {'Cookie': 'KLSE=' + cookie},
muteHttpExceptions: true
}
);
var match = response.getContentText().match(/id="price"[^>]*data-value="([^"]+)"/);
return match ? parseFloat(match[1]) : 'Error';
}
Step 3: Use this formula, replace 6888 with your own stock code, or assuming your stock code is in the cell B22:
=KLSE(6888)
=KLSE(B22)
And this is for SGX, just replace the stock code (e.g. G3B, CFA) with whatever ticker you want, or , or assuming your stock code is in the cell B22:
=IMPORTXML("https://growbeansprout.com/quote/G3B.SI", "//p[@class='text-3xl font-medium']")
=IMPORTXML("https://growbeansprout.com/quote/"&B22&".SI", "//p[@class='text-3xl font-medium']")
You can use this formula to approximate USD per oz (approx. 31.1g):
=GOOGLEFINANCE("GLD", "price")*10/POW(0.996,YEARFRAC(TODAY(), "18/11/2004", 1))
GLD is the ticker for SPDR gold trust ETF, the largest one out there. They charge 0.4% per annum since inception.
I have been updating this article over time, I first posted this a few years before LLM is a thing.
But these days, whenever the formulae in my own sheets broke, I turned to Google/Gemini, ChatGPT, and Claude asking for help. Sadly they often responded to me, either:
GOOGLEFINANCE("MYX:xxx") - this counter doesn't exist, Google has definitely hallucinated.They know my name is Anonoz, it did not occur to these AIs to wonder "why is anonoz asking these and maybe he wants to see smtg else".
Luckily, I am a software engineer who is well versed enough with web techs, and I can just get these LLM to come up with solutions based on my hunches, the KLSE script is one such example - generated by Claude Code.