Тянем просмотры с vc.ru

mail@pastecode.io avatar
unknown
javascript
a year ago
766 B
49
Indexable
Never
function updateViews() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var data = sheet.getRange("B1:C" + sheet.getLastRow()).getValues();
  
  for (var i = 0; i < data.length; i++) {
    var url = data[i][0];
    
    if (url !== "") {
      var response = UrlFetchApp.fetch(url);
      var content = response.getContentText();
      
      var match = content.match(/<span class="views__value">([\d\s,&nbsp;]+)<\/span>/);
      if (match) {
        var viewsValue = match[1].replace(/\s|&nbsp;|,/g, "");
        sheet.getRange(i + 1, 3).setValue(viewsValue); // Update corresponding cell in column C
      }
    }
  }
}

function setupTrigger() {
  ScriptApp.newTrigger('updateViews')
    .timeBased()
    .everyHours(1)
    .create();
}