0

I am trying to get some data from this page https://agones.gr with importhtml for record purposes , but when the day have to many games it is impossible to get the data (usually it happens on Saturday where are to many games . Is there any other way to do that. Any help will be appreciated.

nikosthe15
  • 21
  • 1
  • 3

1 Answers1

2

When the array is too large, you cannot use importltml. Instead, you can do it by script:

function importTableHTML(url) {
  var html = '<table' + UrlFetchApp.fetch(url).getContentText().replace(/(\r\n|\n|\r)/gm,"").match(/(?<=\<table).*(?=\<\/table)/g) + '</table>';
  var trs = [...html.matchAll(/<tr[\s\S\w]+?<\/tr>/g)];
  var data = [];
  for (var i=0;i<trs.length;i++){
    var tds = [...trs[i][0].matchAll(/<(td|th)[\s\S\w]+?<\/(td|th)>/g)];
    var prov = [];
    for (var j=0;j<tds.length;j++){
      donnee=tds[j][0].match(/(?<=\>).*(?=\<\/)/g)[0].replace(/&nbsp;/g,' ');
      prov.push(stripTags(donnee));
    }
    data.push(prov);
  }
  return(data);
}

function stripTags(body) {
  var regex = /(<([^>]+)>)/ig;
  return body.replace(regex,"");
}

https://docs.google.com/spreadsheets/d/16VY07Zb4y5-yOzIJvCdKRxsX7pdCocFq8RGCgDsrmdc/copy

Mike Steelson
  • 14,650
  • 2
  • 5
  • 20
  • I appreciate your help Mike Steelson, that seems to work just fine. I have only one question. What is the checkbox is used for? I am not any good in code and I don't fully understand it. Is it to change from importhtml to the script? – nikosthe15 Aug 29 '21 at 10:43
  • 1
    You can forget about the checkbox and remove it from the formula. I actually use it as an extra parameter (which is not called by the custom function) to update the result while developing the script. It can also be used to update at a certain frequency just by changing the value of the checkbox by a triggered script. Hope this explanation is clear (sorry I am French) – Mike Steelson Aug 29 '21 at 12:17
  • This is great. What if I want to fetch only the second or third table on the page? – Daniel Westergren Aug 25 '23 at 15:23