How to Import International Stock Price Data into Google Sheets using IMPORTXML

KuyaChris
3 min readOct 10, 2020

I’ve been using GOOGLEFINANCE but it doesn’t work with stocks in the international market, specifically the Philippines.

Additionally, previous posts suggested using IMPORTXML with Bloomberg.com, but it seems Bloomberg has changed their code to prevent people from pulling information from their pages. At least it didn’t work for me.

Here’s another option using MarketWatch.com

Navigate to the stock you want to track. We will use Ayala Land Inc. (ALI) in the Philippines for this example:
(https://www.marketwatch.com/investing/Stock/ALI?countryCode=PH)

This URL link will be the first part of the IMPORTXML formula.

Right click and select Inspect while using the Chrome or Brave browser.

Hover over the code in the Elements panel and navigate to the section you want information from. For this example, we’re pulling the current stock price. Once you’re directly at the specific element, right click and navigate to Copy > Copy XPath.

EDIT: For other sites, you may try to use “Copy full XPath”

This XPATH will be the second part of the IMPORTXML formula.

Now navigate to your Google Sheet and use the IMPORTXML formula in the cell you want the specific data (stock price) to be displayed.

=IMPORTXML("INSERT URL HERE", "INSERT XPATH HERE")

For our above example, this would be the code:

=IMPORTXML("https://www.marketwatch.com/investing/Stock/ALI?countryCode=PH", "/html/body/div[3]/div[2]/div[3]/div/div[2]/h3/span")

And tadah! Simple enough. Just rinse and repeat for the other stocks you want listed. Just make sure you’re using the same site and the specific page of each stock—in this case, on MarketWatch.com

Hope that helps!

EDIT: For some reason, the XPath on MarketWatch.com changes intermittently and results in errors.

My suggestion is to have the XPath in a single cell that you can easily change and then reference that cell for your =IMPORTXLM formula.

In this case, the C1 cell has this formula:

=IMPORTXML(B3, $B$1)

Now you can easily change the XPath in cell B1 if there’s ever an error.

--

--

KuyaChris

Filipino American creative. Host of The Filipino Garage podcast available on iTunes & Spotify. Visit KuyaChris.com for more info 🙏🏾🇵🇭