-
-
Save erajanraja24/a6d4add4bd9eb2817f8b05f0863bbf37 to your computer and use it in GitHub Desktop.
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) | |
} | |
} |
need help fixing this code
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 = /<div id="upsell-message.*/div>/gi
var getContent = UrlFetchApp.fetch(url).getContentText().trim();
var price = getContent.match(regEx)
price = price[0]
scraperSheet.getRange(i, 2).setValue(price)
}
}
Hi.
First off, thanks to @erajanraja24 for creating a video and helping a no code experience guys accomplish this task.
The current amazon.in page has a new price expression:
1,03,990.

i was able to make some changes in the code and get the desired results -
Scrape price of Amazon.in website for selected ASINS as of October 2024
Happy to share the code.
Note: what worked for me is to watch the video and code alongside, it will help in understanding the concept and prepare you if any changes in the HTML data of amazon happens, and they certainly will.
Video Link: https://www.youtube.com/watch?v=wt_WpfaUom8&t=919s
Hopefully make my video soon too!
Google Sheet Name: Scraper
Sheet1: Scraper
Sheet2: Settings
`function scraper()
{
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.in/dp/"+scraperSheet.getRange(i, 1).getValue()
var priceRegExp = /(.*?)></span>/gi
var getContent = UrlFetchApp.fetch(url).getContentText().trim();
var price = getContent.match(priceRegExp)
var price = price[0]
price = price.replace('',"")
.replace('.',"")
scraperSheet.getRange(i, 2).setValue(price)
}
}
`
how to get the delivery time in the product page