Home > Blockchain >  Grab data from website HTML table and transfer to Google Sheets using App-Script
Grab data from website HTML table and transfer to Google Sheets using App-Script

Time:01-28

Ok, I know there are similar questions out there to mine, but so far I have yet to find any answers that work for me. What I am trying to do is gather data from an entire HTML table on the web (enter image description here

Other solution by script

function importTableHTML() {
  var url = 'https://www.sports-reference.com/cbb/schools/indiana/2022-gamelogs.html'
  var html = '<table'   UrlFetchApp.fetch(url, {muteHttpExceptions: true}).getContentText().replace(/(\r\n|\n|\r|\t|  )/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];
      prov.push(stripTags(donnee));
    }
    data.push(prov);
  }
  return(data);
}
function stripTags(body) {
  var regex = /(<([^>] )>)/ig;
  return body.replace(regex,"");
}

enter image description here

  •  Tags:  
  • Related