【发布时间】:2021-02-19 02:52:38
【问题描述】:
我正在尝试使用 JSON 来提取 Spotify 播放列表上的关注者。 似乎各种播放列表具有不同的 HTML 数据 - 这使得它变得复杂。
这是我目前在 Google Apps 脚本中的代码。 (@Tanaike 提供)
function SAMPLE(url) {
const res = UrlFetchApp.fetch(url).getContentText();
const v = res.replace(/&/g, "&").match(/Spotify\.Entity \=([\s\S\w]+?);/);
return v && v.length == 2 ? JSON.parse(v[1].trim()).followers.total : "Value cannot be
retrieved.";
}
然后我只是在单元格中使用 =SAMPLE(链接)
但是,我在某些播放列表链接上收到此错误(我不知道为什么): SyntaxError:JSON 输入意外结束(第 4 行)。
工作链接示例: https://open.spotify.com/playlist/5aSO2lT7sVPKut6F9L6IAc https://open.spotify.com/playlist/7qvQVDnLe4asawpZqYhKMQ
无效链接示例(显示上述错误) https://open.spotify.com/playlist/2Um96ZbAH1fFTHmAcpO50n https://open.spotify.com/playlist/68jtRFcWtaFNHKO5wYLBsk
大约 80% 的链接有效(我有超过 400 个)。任何指导或帮助将不胜感激。
谢谢大家!
【问题讨论】:
标签: json google-apps-script google-sheets