Created
June 28, 2017 16:40
-
-
Save X0nic/1fa8334dd3ab7622bba42bde1c98579c to your computer and use it in GitHub Desktop.
Revisions
-
X0nic created this gist
Jun 28, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ // 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(); }); });