Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bran921007/9ffef03831db25b08d6cd275bcdcd633 to your computer and use it in GitHub Desktop.
Save bran921007/9ffef03831db25b08d6cd275bcdcd633 to your computer and use it in GitHub Desktop.
Amazon product price Scraper
function scraper() {
/* Create two sheets with name "Settings" and "Scraper".Put your API key in the Setting tab B1 and put your ASIN list
in the Scraper tab*/
var apiKey = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Settings").getRange(1, 2).getValue();
var scraperSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Scraper")
var lrow = scraperSheet.getLastRow();
for(var i=2;i<=lrow;i++){
var url = "http://api.scraperapi.com?api_key=" + apiKey + "&url=https://www.amazon.com/dp/"+scraperSheet.getRange(i, 1).getValue()
var regEx = /<span id="priceblock_ourprice.*<\/span>/gi
var getContent = UrlFetchApp.fetch(url).getContentText().trim();
var price = getContent.match(regEx)
price = price[0]
price = price.replace('<span id="priceblock_ourprice" class="a-size-medium a-color-price priceBlockBuyingPriceString">',"")
.replace('</span>',"")
scraperSheet.getRange(i, 2).setValue(price)
}
}
@maheshnandyala
Copy link

Screenshot 2019-11-08 at 12 40 41 AM

what mean this error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment