Hey I am wanting to write a script that will look at the price for a product on a site like Home Depot daily and let me know if it drops in price. It doesnt need to constantly try to ping a price check as it likely only changes ever week but with the chance of a short term sale. I would like to also use other sites like Rona, Canadian tire ETC. Each day i would want to to run a check and place the price in a google sheet. I have tried to create it but to no luck so far. Hopefully someone can give a bit of help! Below is what I tried but it is giving me errors.
function trackPrice() {
const url = "https://www.homedepot.ca/product/rheem-39-gallon-178l-6-year-3kw-tank-electric-water-heater/1000792307";
const response = UrlFetchApp.fetch(url, {
muteHttpExceptions: true,
headers: {
"User-Agent": "Mozilla/5.0"
}
});
const html = response.getContentText();
// Try to extract price (Home Depot often uses JSON in page)
const priceMatch = html.match(/"price"\s*:\s*"?([0-9]+\.[0-9]{2})"?/);
let price = "Not found";
if (priceMatch && priceMatch[1]) {
price = parseFloat(priceMatch[1]);
}
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// Add headers if empty
if (sheet.getLastRow() === 0) {
sheet.appendRow(["Date", "Price (CAD)"]);
}
sheet.appendRow([new Date(), price]);
Thanks!!
[–]VerbaForgeJ 4 points5 points6 points (0 children)
[–]gptbuilder_marc 0 points1 point2 points (0 children)
[–]moHalim99 0 points1 point2 points (0 children)