0
votes

I am following this in order to determine aapl 5 year growth rate and insert into a google sheet. It works fine for calculating basic share price e.g this =IMPORTXML("https://finance.yahoo.com/quote/AAPL?p=AAPL&.tsrc=fin-srch","//*[@id='quote-header-info']/div2/div1/div/span1")

However when using the same process to calculate 5 year growth rate (which can be seen on this page (and image below) the process doesnt work and google sheets throws an error (Resource at URL not found). This is the formula I am using =IMPORTXML("https://finance.yahoo.com/quote/Aapl/analysis","//*[@id='Col1-0-AnalystLeafPage-Proxy']/section/table[6]/tbody/tr[5]/td2")

Any idea why and if this is possible ?

enter image description here

2

2 Answers

1
votes

We are at the mercy of a company changing their websites and sometimes what used to work stops working. I could not even get the first one to return data that you stated worked.

enter image description here

Check out this sheet that I saw somebody post here, I am not sure it has the specific stats you want. I have also not studied this sheet closely, but it does use json and a small script to work it's magic.

https://docs.google.com/spreadsheets/d/1_YfvUIvVLjCqKpGuWM3TYqT1HEco0UascTZcyR2fqjI/edit#gid=896982005

Feel free to make a copy.

1
votes

If you specifically want the next 5 year growth :

function growthEstimate(code){
  var url='https://finance.yahoo.com/quote/'+code+'/analysis'
  var source = UrlFetchApp.fetch(url).getContentText()
  var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}'
  var data = JSON.parse(jsonString)
  return data.context.dispatcher.stores.QuoteSummaryStore.earningsTrend.trend[4].growth.fmt
}
function test(){
  Logger.log(growthEstimate('AAPL'))
}