PhantomJS onResourceReceived no stream

我的未来我决定 提交于 2020-01-06 19:42:35

问题


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?


回答1:


PhantomJS (versions 1 and 2) doesn't support <audio>, <video> or flash. You won't see the requests that you expect, because they are not sent.

SlimerJS which has the same API as PhantomJS uses the Gecko engine and supports <audio> and <video>.



来源:https://stackoverflow.com/questions/28742292/phantomjs-onresourcereceived-no-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!