将JavaScript表格导入Google文档电子表格 [英] Importing javascript table into Google Docs spreadsheet

查看:128
本文介绍了将JavaScript表格导入Google文档电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在pgatour.com/leaderboard.html或golf.com/leaderboard中导入排行榜(对不起,由于我的信誉<10,不能发布超过2个链接)。

I am attempting to import the leaderboard at pgatour.com/leaderboard.html or golf.com/leaderboard (sorry, can't post more than 2 links since I have <10 reputation).

根据我的研究,似乎IMPORTHTML& IMPORTXML函数无法检索数据,因为在导入函数运行时表并不存在,因为在函数读取页面的html / xml后,通过javascript加载表/数据。示例:

Based on my research, it seems that the IMPORTHTML & IMPORTXML functions are unable to retrieve the data because the table doesn't actually exist at the time the import function runs, as the table/data is loaded via javascript after the function reads the page's html/xml. Example:

=IMPORTXML("http://www.golf.com/leaderboard","//*[@id='leaderboardPositionTable']")
=IMPORTHTML("http://www.pgatour.com/leaderboard.html","table",1)

是否有人知道将这种表格拉入Google Docs电子表格的方法?我试着按照这里的建议,但老实说如果导入JSON是正确的方法,或者如果我甚至正确地做到这一点,那么我们就不会有任何线索。

Is anyone aware of a way to pull such a table into a Google Docs spreadsheet? I tried to follow the advice here, but honestly don't have a clue if importing JSON is the right approach, or if I'm even doing it correctly.

任何帮助都将不胜感激。谢谢

Any help would be much appreciated. Thanks

推荐答案

考虑到这一点后,我认为你应该采取以下方法。事实证明,排行榜可用作JSON文件。

After looking into this, I think you should take the following approach. It turns out that leaderboard is available as a JSON file. I wrote a function to test out the import and it works well.

function update_leaderboard(){
  var url = "http://www.pgatour.com/data/r/033/leaderboard-v2.json?ts=" + new Date().getTime()
  var result = UrlFetchApp.fetch(url);
  var response = result.getContentText();
  var data = JSON.parse(response);
  var w = SpreadsheetApp.getActive();
  var s = w.getActiveSheet();
  s.clear();
  //Write the JSON to the spreadsheet...
}

得到了那么多,唯一剩下要做的就是将这些信息写入电子表格。

Having gotten that far, the only thing left to do is write that information onto the spreadsheet.

这篇关于将JavaScript表格导入Google文档电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆