Created
March 16, 2014 19:28
-
-
Save kylewelsby/9588485 to your computer and use it in GitHub Desktop.
Using PhantomJS to check if F1 is available to watch or not.
This file contains 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 characters
(function () { | |
'use strict'; | |
var page; | |
page = require('webpage').create(); | |
page.onResourceRequested = function(requestData, request) { | |
if ((/http:\/\/.+?\.(css|png|js|jpg|gif)/gi).test(requestData['url']) || requestData['Content-Type'] == 'text/css') { | |
request.abort(); | |
} | |
}; | |
page.onError = function () { | |
}; | |
function check() { | |
console.log('['+new Date().toISOString() + '] Checking'); | |
page.open('http://www.bbc.co.uk/programmes/b03yrh8r', function () { | |
// page.open('http://www.bbc.co.uk/programmes/b03yms67', function () { | |
var isAvailable = page.evaluate(function () { | |
return document.querySelector('.availability .message .text') === null; | |
}); | |
if(isAvailable) { | |
console.log('['+new Date().toISOString() + '] Available!'); | |
phantom.exit(); | |
} else { | |
setTimeout(function(){ | |
phantom.exit(); | |
},1000); | |
} | |
}); | |
} | |
check(); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment