“Attribute provided with no value” error - UrlFetchApp

馋奶兔 提交于 2020-07-09 14:51:10

问题


I have the following error :

Attribute provided with no value

The error is from line:

var content = UrlFetchApp.fetch(url).getContentText();

Here is my code :

function getArray() {
  var newData = new Array();
  var sheet = SpreadsheetApp.openById('my_id').getSheetByName('Sheet2');
  var urls = sheet.getRange("A1:A").getValues();
  var fromText = '<span class="nb-shares">';
  var toText = '</span>';

  for(var i = 0; i < urls.length; i++){
    var url = urls[i];
    var content = UrlFetchApp.fetch(url).getContentText();
    var scraped = Parser
                   .data(content)
                   .from(fromText)
                   .to(toText)
                   .build();
         newData.push([scraped]);
  }

  var sheet2 = SpreadsheetApp.openById('my_id').getSheetByName('Sheet5'); 
  sheet2.getRange(1, 1, newData.length, newData[1].length).setValues(newData);
}

回答1:


The getValues() method returns a 2 dimensional array. You are not getting the value out of the inner array.

Currently:

var url = urls[i];

Should be:

var url = urls[i][0];

You need to add the [0] index for the inner array.




回答2:


If your suspicion is that urls is not a proper array than you can just console.log(urls) after you define it and see if it is an array or something else.

Or test like this console.log(Array.isArray(urls))



来源:https://stackoverflow.com/questions/39781699/attribute-provided-with-no-value-error-urlfetchapp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!