Skip to content

Instantly share code, notes, and snippets.

@kylewelsby
Created March 16, 2014 19:28
Show Gist options
  • Save kylewelsby/9588485 to your computer and use it in GitHub Desktop.
Save kylewelsby/9588485 to your computer and use it in GitHub Desktop.
Using PhantomJS to check if F1 is available to watch or not.
(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