Advertisement
RemcoE33

Subeta

Jul 26th, 2021
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onOpen(e){
  2.   SpreadsheetApp.getUi().createMenu('Subeta')
  3.     .addItem('Run', 'Subeta')
  4.     .addToUi()
  5. }
  6.  
  7. function Subeta() {
  8.   console.time('Start20');
  9.   const activeSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1')
  10.   //const values = activeSheet.getRange(2,1,activeSheet.getLastRow() -1).getValues().flat();
  11.   const values = activeSheet.getRange(2,1,20).getValues().flat();
  12.  
  13.   const output = [];
  14.  
  15.   values.forEach(item => {
  16.     try{
  17.     const res = UrlFetchApp.fetch(encodeURI(`https://www.subetalodge.us/view/item/${item}`))
  18.     const html = res.getContentText();
  19.     const price = /Official Price<\/b>:(.*?)sP/gmis.exec(html)[1];
  20.     console.log(price)
  21.     output.push([Number(price.trim().replace(',','.'))]);
  22.     } catch (err){
  23.       output.push(['Error'])
  24.     }
  25.   })
  26.  
  27.   activeSheet.getRange(2,7, output.length, 1).setValues(output);
  28.   console.timeEnd('Start20');
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement