如何解决使用 VBA 提取 html 中的 JSON DATA 表;将 Apps 脚本转换为 VBA
我想使用 VBA 从 https://s.cafef.vn/screener.aspx#data 的 URL 中检索一个表。这项任务很困难,因为该表包含嵌入在 html 文件中的 JSON 数据,但它是如此善良,一位 GAS 专家帮助我为 Google Apps 脚本创建了一个自定义函数。 (IMPORTHTML() doesn't work in this webpage structure) 函数如下:
function SAMPLE(url) {
const res = UrlFetchApp.fetch(url,{muteHttpExceptions: true});
const html = res.getContentText().match(/var jsonData \=([\S\s\w]+\}\])/);
if (!html) return "No tables. Please confirm URL again.";
const table = JSON.parse(html[1].replace(/\n/g,""));
const header = ["","FullName","Symbol","CenterName","ChangePrice","VonHoa","ChangeVolume","EPS","PE","Beta","Price"];
return table.reduce((ar,e,i) => {
const temp = header.map(f => f == "" ? i + 1 : e[f]);
ar.push(temp);
return ar;
},[header]); }
此函数在 Google Sheets 环境中完美运行,但我现在的目标是将其转换为 VBA,或者换句话说,编写一个可以获取 https://s.cafef.vn/screener.aspx#data 表的 VBA 模块。
非常感谢您的任何帮助或建议
曹多雷米
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。