使用 ImportHTML 查找 table

Finding a table using ImportHTML

我觉得我已经尝试了这里的所有解决方案,但尚未完成此任务。

我想在这个 link:

上争取第二次(季后赛)table

https://www.basketball-reference.com/players/c/curryst01/gamelog/2016

第一个 table 使用 IMPORTHTML 很容易进入,第二个但是我找不到。

我已经尝试将 IMPORTHTML 与 100 个不同的 table 和列表一起使用。我还查看了 inspector 并在

我读到这可能是因为它是一个 Javascript 对象,但是当我关闭 Javascript 时(就像有人建议的那样),我仍然看到 table,这导致我相信它绝对可以被刮成 Google Sheet.

我也试过 ImportXML,但我不太熟悉,也找不到相关信息。

有什么关于如何抓取它的建议吗?这么难我觉得很奇怪!

我知道我没有正确关闭 Javascript...好吧,现在 table 不见了。所以我假设这意味着它不能被刮到表格中。

仍然很好奇那里有什么解决方案 - 我目前正在使用 ParseHub 进行研究,但我真的很想了解如何在 Sheets 中完成它

不幸的是,IMPORTHTML 和 IMPORTXML 似乎不能用于检索您期望的 table。但是,幸运的是,我注意到当 HTML 由 Google Apps 脚本检索时,HTML 数据包含您期望的 the SECOND (playoffs) table 的 table。所以在这个答案中,我想建议使用 Google Apps Script。

示例脚本:

请将以下脚本复制并粘贴到 Google Spreadsheet 和 please enable Sheets API at Advanced Google services 的脚本编辑器中。并且,请在脚本编辑器中 运行 myFunction。这样,检索到的 table 被放入 sheet.

function myFunction() {
  const url = "https://www.basketball-reference.com/players/c/curryst01/gamelog/2016"; // This URL is from your question.
  const sheetName = "Sheet1";  // Please set the destination sheet name.

  const html = UrlFetchApp.fetch(url).getContentText();
  const tables = [...html.matchAll(/<table[\s\S\w]+?<\/table>/g)];
  if (tables.length > 8) {
    const ss = SpreadsheetApp.getActiveSpreadsheet();
    Sheets.Spreadsheets.batchUpdate({ requests: [{ pasteData: { html: true, data: tables[8][0], coordinate: { sheetId: ss.getSheetByName(sheetName).getSheetId() } } }] }, ss.getId());
    return;
  }
  throw new Error("Expected table cannot be retrieved.");
}

结果:

当此脚本为运行时,可得到如下结果

参考文献:

试试这个,它会给你主要的 table

=importhtml(url,"table",8)

您还可以检索 tables #1 到 #7

的信息