I love using Google Sheet to track my stock purchases and portfolio. You can get a copy of my Portfolio Tracker here.
One thing I struggle with for Singapore stocks is that the stock data are not available on Google Finance. So then, how can I get the stock price without updating it manually on my google sheet?
Using the IMPORTXML function
IMPORTXML function, you can, in simple terms, scrap data from another website into your google sheet.
Example: Get DBS price without Google Finance for Singapore Stock
So in my case, I want to get the price of e.g. DBS.
- Find out what is the DBS stock code: D05.
- Find out a website that has DBS stock price. e.g.
- Find out the XPATH of the price data. (This is a little technical, will go more into details later)
Using the above information, you can now get the updated price for Singapore stocks without using Google Finance.
You can access the example on googlesheet here. This is a view only link.
I have added 3 different sites in which you can scrape the price data of Singapore stock without google finance.
Just Make a copy of it and you will be able to edit it.
Why is the price not showing?
I do noticed that sometimes it takes a while of the price to load up. Or sometimes the site gets updated, so the XPATH has changed. Or other times, it could be that the site you are trying to scrape the data from doesn’t allow importxml anymore. This is not a fool proof way to get data, but I think its the best free way for me to manage my portfolio.
How to retrieve the XPATH?
Read on if you want to know the technical part.
I would suggest to read up a bit on XPATH so if you don’t know what XPATH is. Once you have a little bit of understanding, you can then try this. So for our example to retrieve the price for DBS, we have the URL which has the stock price.
Right click on the Price -> Inspect
This should open up the DEVTOOLS for chrome or Edge browser. And it will highlight which element that is.
So in this example, you can see that the price resides in the
<span> tag, and lucky for us, there is a attribute called
data-reactid = "32".
You need to test out if the XPATH is unique by CTRL+F on the devtool and you will see this Find by string, selector or XPath search box appear. Make sure that the search result is 1 of 1 which means it’s unique in this page.
Drop me a comment if there are any other questions or if there are better ways to do it, I would love to hear about it.