首页 > 解决方案 > 雅虎财经:使用 Google 表格公式检查浮动

问题描述

我想要一个公式来获取例如 BEKB.BR https://finance.yahoo.com/quote/BEKB.BR/key-statistics?p=BEKB.BR的浮点数, 它是 36.45M 公式之类的

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

或单元格 A27 中的代码:

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

不要给出结果。谢谢你的帮助。

标签: google-sheetsfinancestockyahoo

解决方案


IMPORTHTML()and函数不会以IMPORTXML()我不明白为什么的方式获取此页面。

您可以改为在 Google Apps 脚本中使用 URLFetchApp。

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)
}

是一个工作示例。当您单击按钮时,它将浮点值写入 A1 单元格。


推荐阅读