javascript - Testing an MP3 with PhantomJS -


i want set testing routine in phantom scans podcast rss feed, grabs urls of mp3 files, tests see exist. have this:

/* checking 1 mp3 file */ function checkfile(url) {       var fs = require('fs');      if (fs.exists(url)) {         console.log('"'+url+'" exists.');     } else {         console.log('"'+url+'" doesn\'t exist.');     } }  /* checking whole feed */ page.open('/path/to/rss/', function(status) {     if (status === 'fail') {         console.log(status);     } else {         var content = page.content;         parser = new domparser();         xmldoc = parser.parsefromstring(content,'text/xml');         var item = xmldoc.getelementsbytagname('item');         console.log('feed contains ' + item.length + ' items');          var enclosures = xmldoc.getelementsbytagname('enclosure');         for(var i=0; < enclosures.length; i++)          {             var enclosureattributes = enclosures[i].attributes;             var url = enclosureattributes.getnameditem("url").value;             console.log('checking: ' + url);             checkfile(url);         }     }     phantom.exit(); });  

however fs.exists() function returns false. mp3 files download directly in browser instead of playing, maybe that's problem. or maybe it's not allowing enough time.

the fs module name says file system module. can't access remote files it.

you either have use page.open() , see status passed callback (it's asynchronous: can't use loop here). or can use non-async xmlhttprequest inside of page.evaluate() (you have run phantomjs --web-security=false if files on domain).


Comments