I am trying to receive the URL of a mpeg live stream. Because the url of streams might change, but a site rarely does, I am using onResourceReceived to listen for the url of the stream.
So far, I have not been getting anything (not even errors). Here is my code:
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1) {
console.log('Usage: netlog.js <some URL>');
phantom.exit(1);
} else {
address = system.args[1];
page.onResourceRequested = function (req) {
console.log('requested: ' + JSON.stringify(req, undefined, 4));
};
page.onConsoleMessage = function(msg) {
system.stdout.writeLine('console: ' + msg);
};
page.onResourceReceived = function (res) {
console.log('received: ' + JSON.stringify(res, undefined, 4));
};
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
}
var radio = page.evaluate(function() {
return document.getElementById('button_playpause');
});
console.log('Radio variable: ');
console.log(radio);
console.log('Clicking button: ');
$(radio).click();
phantom.exit();
});
}
I adapted the code found here: http://phantomjs.org/network-monitoring.html The website I am trying this code on is the following: http://radioplayer.npo.nl/mini-player/radio4/
Why does the url not show up when PhantomJS clicks the button?