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

如何在Google Sheets中批量提取YouTube频道名称?

批量从YouTube频道URL提取频道名称(Google Sheets方案)

针对25000条YouTube频道URL的批量提取需求,普通公式(如IMPORTXML)易因页面结构变化、反爬限制或API配额问题返回N/A,推荐使用Google Apps Script自定义函数解决,步骤如下:

操作步骤

  1. 打开你的测试表格,点击顶部菜单栏「扩展程序」>「Apps Script」,进入脚本编辑器。
  2. 删除默认的myFunction代码,替换为以下脚本:
function GET_YOUTUBE_CHANNEL_NAME(url) {
  if (!url) return "";
  
  // 提取频道ID:支持/channel/、@用户名、/c/三种常见格式
  let channelId = null;
  const channelMatch = url.match(/channel\/([a-zA-Z0-9_-]+)/);
  const atMatch = url.match(/@([a-zA-Z0-9_-]+)/);
  const cMatch = url.match(/c\/([a-zA-Z0-9_-]+)/);
  
  if (channelMatch) {
    channelId = channelMatch[1];
  } else if (atMatch) {
    // 通过用户名获取频道ID
    try {
      const response = YouTube.Channels.list("snippet", {forUsername: atMatch[1]});
      if (response.items.length > 0) {
        channelId = response.items[0].id;
      }
    } catch (e) {
      return "无法获取频道ID";
    }
  } else if (cMatch) {
    // 处理/c/格式,需要先转成频道ID
    try {
      const response = YouTube.Search.list("id", {q: cMatch[1], type: "channel", maxResults: 1});
      if (response.items.length > 0) {
        channelId = response.items[0].id.channelId;
      }
    } catch (e) {
      return "无法获取频道ID";
    }
  }
  
  if (!channelId) return "无效频道链接";
  
  // 获取频道名称
  try {
    const channelResponse = YouTube.Channels.list("snippet", {id: channelId});
    if (channelResponse.items.length > 0) {
      return channelResponse.items[0].snippet.title;
    } else {
      return "频道不存在";
    }
  } catch (e) {
    return "请求错误:" + e.message;
  }
}
  1. 点击脚本编辑器顶部的「保存」按钮,给脚本命名(如「YouTube频道提取工具」)。
  2. 首次运行会弹出授权请求,按提示完成授权(需允许脚本访问YouTube数据)。
  3. 返回表格,在B2单元格输入=GET_YOUTUBE_CHANNEL_NAME(A2),按下回车后即可提取A2单元格链接的频道名称,下拉填充公式到所有行即可批量处理。

注意事项

  • API配额限制:Google账号默认每日YouTube API配额为10000单位,Channels.list调用消耗1单位,Search.list调用消耗100单位。若你的链接多为/channel/格式,可一次性处理完25000条;若包含大量@或/c/格式链接,需分多天处理,或前往Google Cloud控制台申请提高配额。
  • 异常处理:脚本会对无效链接、私有频道、已删除频道返回对应提示,便于排查问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 07:38:35