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

如何将Old School RuneScape维基表格图片导入Google Sheets?

解决Google Sheets导入OSRS低等级怪物图鉴图片的方法

1. 先导入表格基础数据

先用你原来的公式把页面里的表格文字数据导入到Sheet中:

=IMPORTHTML("https://oldschool.runescape.wiki/w/Bestiary/Levels_1_to_10","table","1")

这一步会得到怪物名称、等级、生命值等数据,但图片列是空的,接下来用脚本补全图片。

2. 用Google Apps Script抓取并插入图片

Google Sheets内置公式无法直接导入图片,得用脚本实现:

  • 打开你的Google表格,点击顶部「扩展程序」>「Apps Script」
  • 删除编辑器里的默认代码,粘贴下面的脚本:
function importMonsterImages() {
  const targetUrl = "https://oldschool.runescape.wiki/w/Bestiary/Levels_1_to_10";
  const pageHtml = UrlFetchApp.fetch(targetUrl).getContentText();
  const xmlDoc = XmlService.parse(pageHtml);
  const rootElement = xmlDoc.getRootElement();

  // 定位页面里的目标表格(和IMPORTHTML指定的第一个表格匹配)
  const targetTables = rootElement.getDescendants().filter(node => {
    const element = node.asElement();
    return element && element.getAttribute("class")?.getValue().includes("wikitable");
  });
  if (targetTables.length === 0) return;

  const monsterTable = targetTables[0].asElement();
  const tableRows = monsterTable.getChildren("tr");
  const activeSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

  // 遍历表格行(跳过表头行)
  for (let rowIndex = 1; rowIndex < tableRows.length; rowIndex++) {
    const rowCells = tableRows[rowIndex].getChildren("td");
    if (rowCells.length < 1) continue;
    
    // 提取第一列的图片URL(页面里图片在表格第一列)
    const imgCell = rowCells[0];
    const imgTag = imgCell.getChild("img");
    if (imgTag) {
      const imgSrc = imgTag.getAttribute("src").getValue();
      // 插入图片到对应单元格,设置大小为32x32(和wiki里的图标尺寸一致)
      const targetCell = activeSheet.getRange(rowIndex + 1, 1);
      activeSheet.insertImage(imgSrc, targetCell.getColumn(), targetCell.getRow())
        .setWidth(32)
        .setHeight(32);
    }
  }
}
  • 点击编辑器顶部的「保存」按钮,给脚本起个名字(比如MonsterImageImporter)
  • 点击「运行」,第一次运行会弹出授权提示,按照步骤完成授权(需要允许脚本访问你的表格和外部URL)
  • 运行完成后,表格的第一列就会自动插入对应的怪物图标

3. 适配调整

  • 如果图片显示大小不合适,修改脚本里的setWidth(32)和setHeight(32)数值即可
  • 若页面表格结构变化,调整rowCells[0]的索引(比如图片移到第二列就改成rowCells[1])

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 15:43:17