Reading the Youtube API from PhantomJS

The following code will retrieve the duration of a video from the Youtube API. The output must be in JSON, because PhantomJS currently doesn’t handle the XML correctly (from email threads it appears this will be fixed in a future release)

address = '' + id + '?v=2&alt=json';, function (status) {
   var duration = page.evaluate(function(){
       var data = JSON.parse(document.querySelector("pre").innerText);
   console.log("video duration: " + duration);

If you want a good Javascript book, I got a lot out of Secrets of the Javascript Ninja.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *