You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

嵌入URL有效性检测脚本误判问题求助

解决Google Apps Script检测失效URL误判问题

针对你遇到的脚本误判问题,核心原因和修复方案如下:

问题根源

  1. 动态内容渲染限制:像Mega这类网站的失效提示是通过JavaScript动态加载的,UrlFetchApp.fetch默认获取的是初始静态HTML,根本包含不了这些动态生成的失效文本。
  2. 请求头未模拟浏览器:部分网站会识别请求来源,对非浏览器的默认UA返回简化内容,导致脚本拿不到完整页面信息。
  3. 短语列表冗余且宽泛:你列表里的access、available这类通用词在正常页面也会出现,反而可能干扰检测;同时缺少部分网站(如Mega)的特定失效提示。

修复方案

1. 修改请求逻辑,模拟浏览器环境

更新getHTTPResponse函数,添加浏览器请求头,让目标网站返回完整页面内容,同时处理请求失败的情况:

function getHTTPResponse(url) {
  var response = "";
  try {
    var options = {
      headers: {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
        'Accept-Language': 'en-US,en;q=0.5'
      },
      followRedirects: true
    };
    response = UrlFetchApp.fetch(url, options).getContentText();
  } catch (e) {
    // 请求直接失败时标记为特殊状态
    return "REQUEST_FAILED";
  }
  return response;
}

2. 优化失效短语列表

删除重复项和通用干扰词,补充Mega等网站的特定失效提示:

var notWorkingPhrases = [
  "File is no longer available as it expired or has been deleted.",
  "has been deleted",
  "File not found",
  "The file expired",
  "This file is not available any more",
  "File no longer accessible",
  "The file you are trying to download is no longer available",
  "File Not Found",
  "The file was deleted by its owner",
  "500 Internal Server Error",
  "Unfortunately, the file you want is not available",
  "video you are looking for is not found",
  "Not Found",
  "claim by 4shared Support Team",
  "of a claim",
  "violation of our",
  "We're sorry.",
  "You need access",
  "File is no longer available",
  "The video has been blocked",
  "This file is not available anymore",
  "The file could not be found", // Mega特定失效提示
  "error\":\"File not found" // Mega静态源码中的错误标记
];

3. 完善检测逻辑

在CheckVideoStatus中增加请求失败的判断,确保所有异常情况都能被正确标记:

function CheckVideoStatus(urlCell) {
  var status = "Working";
  var url = urlCell;

  if (url !== "") {
    var response = getHTTPResponse(url);

    // 优先处理请求失败的情况
    if (response === "REQUEST_FAILED") {
      status = "Not Working";
    } else {
      var isNotWorking = false;
      for (var k = 0; k < notWorkingPhrases.length; k++) {
        if (response.toLowerCase().includes(notWorkingPhrases[k].toLowerCase())) {
          isNotWorking = true;
          break;
        }
      }
      if (isNotWorking) {
        status = "Not Working";
      }
    }
  }
  return status;
}

验证

用你提供的Mega测试链接运行修复后的脚本,就能正确识别为Not Working状态。

内容的提问来源于stack exchange,提问作者simojali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 02:59:56