Forked from erajanraja24/Amazon product price scraper
Created
November 8, 2019 03:31
-
-
Save bran921007/9ffef03831db25b08d6cd275bcdcd633 to your computer and use it in GitHub Desktop.
Amazon product price Scraper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

what mean this error