-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathout-of-stock-scanner.js
More file actions
41 lines (33 loc) · 1.28 KB
/
Copy pathout-of-stock-scanner.js
File metadata and controls
41 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function scanWebsiteForOutOfStockItems() {
const urls = ['https://yourwebsite.com/page1', 'https://yourwebsite.com/page2']; // Add all the URLs you need to scan
const outOfStockItems = [];
// Iterate through each URL and fetch the HTML content
urls.forEach(url => {
const response = UrlFetchApp.fetch(url);
const html = response.getContentText();
// Parse the HTML content
const $ = Cheerio.load(html);
// Assuming out-of-stock items are marked with a specific class, e.g., 'out-of-stock'
$('.out-of-stock').each((index, element) => {
const itemName = $(element).find('.item-name').text().trim(); // Adjust selector as needed
outOfStockItems.push([itemName, url]);
});
});
// Open the target Google Sheet
const sheet = SpreadsheetApp.openById('YOUR_SHEET_ID').getSheetByName('OutOfStock');
// Clear the sheet before adding new data
sheet.clear();
// Add headers to the sheet
sheet.appendRow(['Item', 'Page URL']);
// Append out-of-stock items to the sheet
outOfStockItems.forEach(item => {
sheet.appendRow(item);
});
}
// Set a time-based trigger to run this function hourly
function createHourlyTrigger() {
ScriptApp.newTrigger('scanWebsiteForOutOfStockItems')
.timeBased()
.everyHours(1)
.create();
}