Advertisement
RemcoE33

sports

Aug 3rd, 2022
1,098
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * Returns player stats.
  3. *
  4. * @param {string} url The url
  5. * @return {array} stats about the player.
  6. * @customfunction
  7. */
  8. function FBREF(url ) {
  9.   const request = UrlFetchApp.fetch(url)
  10.   const html = request.getContentText()
  11.   const rows = html.split("</tr>").slice(-13);
  12.  
  13.   const results = [['Date', 'Started', 'Shots total', 'Shots on target', 'Tackless']]
  14.   rows.forEach((row) => {
  15.     try {
  16.       const date = /date[\s\S]*?href[\s\S]*?>(.*?)</gmsi.exec(row)[1]
  17.       const started = /game_started[\s\S]*?>(.*?)</gmsi.exec(row)[1]
  18.       const shotsTotal = Number(/shots_total[\s\S]*?>(.*?)</gmsi.exec(row)[1])
  19.       const shotsOnTarget = Number(/shots_on_target[\s\S]*?>(.*?)</gmsi.exec(row)[1])
  20.       const tackles = Number(/tackles[\s\S]*?>(.*?)</gmsi.exec(row)[1])
  21.  
  22.       results.push([date, started, shotsTotal, shotsOnTarget, tackles])
  23.     } catch (err) {}
  24.   });
  25.   return results
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement