gpt4 book ai didi

javascript - "Attribute provided with no value"错误 - UrlFetchApp

转载 作者:行者123 更新时间:2023-12-03 06:00:05 25 4
gpt4 key购买 nike

我有以下错误:

Attribute provided with no value

错误来自行:

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

这是我的代码:

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);
}

最佳答案

getValues() 方法返回一个二维数组。您没有从内部数组中获取值。

目前:

var url = urls[i];

应该是:

var url = urls[i][0];

您需要为内部数组添加[0]索引。

关于javascript - "Attribute provided with no value"错误 - UrlFetchApp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39781699/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com