使用 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 (将#修改为@)