Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

ImportHTML Script at Bulk

$
0
0

With great help, this script is working to pull in the 2nd table on the below link. The table cannot be scraped with IMPORTHTML unlike the first table (Regular Season works, Playoffs doesn't).

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

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 > 2) {    const ss = SpreadsheetApp.getActiveSpreadsheet();    Sheets.Spreadsheets.batchUpdate({ requests: [{ pasteData: { html: true, data: tables[8][0], coordinate: { sheetId: ss.getSheetByName(sheetName).getSheetId() } } }] }, ss.getId());    Sheets.Spreadsheets.batchUpdate({ requests: [{ pasteData: { html: true, data: tables[7][0], coordinate: { sheetId: ss.getSheetByName(sheetName).getSheetId() } } }] }, ss.getId());    return;  }  throw new Error("Expected table cannot be retrieved.");}`enter preformatted text here`

Now, I have two more issues I'm looking to solve.

  1. Is there a way to tweak this code so both tables 8 and 7 are loading at once? I think my code here fills in with table 8, but then is replaced by table 7. I think because of the batchupdate?

  2. Is there a way to load more than one URL at once. Basically, I want to replicate this code so that 50 URLs can load in the tables at once.

I was previously just using a bunch of IMPORTHTML functions, but because the Playoffs table is a Javascript object, I'm struggling to figure it out.


Viewing all articles
Browse latest Browse all 9782

Trending Articles