Yahoo Finance: working Google Sheets formula to check the Float

Viewed 142

I want a formula to fetch the Float of eg BEKB.BR https://finance.yahoo.com/quote/BEKB.BR/key-statistics?p=BEKB.BR it's 36.45M Formula's like

=index(IMPORTHTML("http://finance.yahoo.com/q/ks?s= BEKB.BR+Key+Statistics","table", 2), 4, 2)

or the ticker in cell A27:

=index(IMPORTHTML("http://finance.yahoo.com/q/ks?s="& $A$27&"+Key+Statistics","table", 2), 4, 2)

don't give a result. Thanks for your help.

1 Answers

The IMPORTHTML() and IMPORTXML() functions don't fetch this page in a way I don't understand why.

You can use URLFetchApp in Google Apps Script instead.

function fetch() {
  url = "https://finance.yahoo.com/quote/BEKB.BR/key-statistics?p=BEKB.BR"
  var response = UrlFetchApp.fetch(url).getContentText()
      
  var index = response.indexOf('8</sup>')
  var subst = response.substr(index,300)
  var float = subst.match(/(?<=reactid="[0-9]+">)[^<]+/)[0]
 
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
  sheet.getRange('A1').setValue(float)
}

Here is a working sample. When you click on the button it writes the Float value to A1 cell.

Related