// I got tired of checking the webpage periodically. var webPage = require('webpage'); var page = webPage.create(); page.onConsoleMessage = function(msg) { console.log(msg); } page.open('http://www.memoryexpress.com/Products/MX64875', function(status) { // page.open('http://www.memoryexpress.com/Products/MX50991', function(status) { page.evaluate(function() { findStock = function() { // console.log('hi'); var el = document.querySelector('#ProductInventory'); var found = el.querySelectorAll('.Title'); // found.forEach( function(e) { for( index=0; index < found.length; index++ ) { invEl = found[index]; if (invEl.innerText == 'Edmonton Region') { // if (invEl.innerText == 'Calgary Region') { // console.log('found emd'); var stock = invEl.parentElement.querySelectorAll('.Availability'); if (stock.length) { var stockMessage = 'South - ' + stock[0].innerText + ': West - ' + stock[1].innerText; if (stockMessage === "South - Out of Stock: West - Out of Stock") { console.log(new Date() + ' |' + document.title + '| ' + stockMessage); setTimeout(findStock, 1000 * 60 * 5); } else { console.log('found stock'); console.log(stockMessage); } } else { console.log('could not find stock'); } } }; } findStock(); }); });