google-sheets - 雅虎财经:使用 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)
不要给出结果。谢谢你的帮助。
解决方案
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 单元格。
推荐阅读
- node.js - 为什么防火墙允许端口连接到某些用户而不是所有用户,尤其是 VPN 用户?
- python-3.x - 以其他列的优先级调整 group by 中的重叠日期
- iis - 将本地服务器驱动器(选定文件夹)映射到 AWS 实例(本地到云)
- r - 将一个 csv 文件拆分为多个 txt。文件
- kubernetes - 我应该每秒进行一次活跃度探测和就绪度探测吗?
- bash - 使用 certbot 更新 Let's Encrypt 证书时出现 AWS 凭证问题
- java - 有谁知道如何解决 Maven 的编译问题?
- python - 期望值浮点数,小数舍入错误
- javascript - Javascript 正则表达式将括号 [] 表示法转换为点表示法
- sql - 加快对两个简单 postgres 表的嵌套循环查询(使用 macaddr 数据类型)