如何使用Google Apps Script获取网站网络请求的URL地址
解决方案
实现逻辑
Google Apps Script 没有内置访问Chrome开发者工具网络请求记录的能力,你不需要依赖浏览器抓包,直接调用站点公开的后端接口即可获取音频直链。
操作步骤
- 从通知邮件提取的讲座页面链接中拿到数字ID:页面链接格式通常为
https://www.torahanytime.com/#/lectures?v=xxxxxx,其中xxxxxx就是唯一的讲座数字ID - 请求站点公开的讲座信息接口:接口地址格式为
https://api.torahanytime.com/lectures/by_id/[讲座数字ID],返回的JSON数据中data.audio字段就是可直接下载的音频直链
修正后的代码
将你的getShiurID函数替换为以下内容:
function getShiurID(email) { const body = email[0].getPlainBody(); const linkBegIndex = body.indexOf("[") + 1; const linkEndIndex = body.indexOf("]"); const lecturePageLink = body.substring(linkBegIndex, linkEndIndex); // 提取链接中的数字ID const shiurNumId = lecturePageLink.match(/v=(\d+)/)[1]; // 调用公开API获取音频地址 const apiRes = UrlFetchApp.fetch(`https://api.torahanytime.com/lectures/by_id/${shiurNumId}`); const lectureInfo = JSON.parse(apiRes.getContentText()); return lectureInfo.data.audio; }
原有逻辑适配
修改main函数中的下载逻辑,直接使用getShiurID返回的完整音频链接调用下载函数即可,无需再手动拼接下载地址前缀:
// main函数中对应的逻辑修改为 const audioDownloadLink = getShiurID(email); const shiur = downloadShiur(audioDownloadLink);
内容的提问来源于stack exchange,提问作者Leo
相关产品推荐
相关产品推荐

