google-sheetsgoogle-sheets-formulayahoo-financegoogle-finance

Trying to use IMPORTHTML or IMPORTXML to get price value from https://finance.yahoo.com/quote/GSPX.L/ in Google Sheets


I'm trying to use IMPORTHTML or IMPORTXML to get price value from https://finance.yahoo.com/quote/GSPX.L/

or in fact from any site that will give me a relatively up-to-date number.

I used to be able to get the value using the GOOGLEFINANCE formula, but that's recently stopped working for a few tickers (not all!)

I've managed to get IMPORTHMTL to work in the past with morningstar.co.uk for some index funds, but the page layout is different with GSPX.L. I've tried using the Full XPath with IMPORTXML but that doesn't seem to work and as far as I understand it IMPORTXML is extremely finnicky.

I just need this one number! Any insight into how to get it, but ideally something more systematic that I can use in the future?


Solution

  • If I am not mistaken, what you want to get is the 7.03 price value from that page. I think there is something on the page blocking Excel and Google Sheets formulas from running on it so it would not be possible to use that site you provided.

    Instead I was able to get it from markets.ft.com. You can use the following formula to get that exact same number:

    =IMPORTXML("https://markets.ft.com/data/etfs/tearsheet/summary?s=GSPX:LSE:GBP", "/html/body/div[3]/div[2]/section[1]/div/div/div[1]/div[2]/ul/li[1]/span[2]")
    

    enter image description here

    References: