问题
function prices() {
var scraperSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("prices")
var lrow = scraperSheet.getLastRow();
for (var i=2;i<=lrow;i++)
{
var regEx = /<span id="priceblock_dealprice.*<\/span>/gi
var getContent = UrlFetchApp.fetch("https://www.amazon.in/"+scraperSheet.getRange(i,1).getValue()).getContentText().trim();
var price = getContent.match(regEx)
price = price[0];
price = price.replace('<span id="priceblock_dealprice" class="a-size-medium a-color-price priceBlockDealPriceString">',"")
.replace('</span>',"")
scraperSheet.getRange(i,3).setValue(price)
}
}
回答1:
The error occurs because
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("prices")
returns null
. In other words, your spreadsheet hasn't a sheet named prices
.
Double check if the argument of the above code line is correct as well is your spreadsheet has the required structure and content.
NOTES:
The following image shows where goes the spreadsheet name and were goes the sheet name
Related
- TypeError: Cannot read property 'pair' of undefined
来源:https://stackoverflow.com/questions/63046368/find-this-error-in-my-code-typeerror-cannot-read-property-getlastrow-of-null