var casper = require('casper').create(); var users = ['mikeyaworski', 'PewDiePie']; // array of YouTube users var j = 0; casper.start(); console.log("\nYouTube:\n"); for (var i = 0; i < users.length; i++) { casper.thenOpen("https://youtube.com/" + users[i], function() { var subscribers = this.evaluate(function() { return document.querySelector('span.yt-subscription-button-subscriber-count-branded-horizontal.subscribed').innerText; }); j++; this.echo(users[j-1] + ":\nSubscribers: " + subscribers); }); casper.thenOpen("https://youtube.com/user/" + users[i] + "/videos?view=0&flow=grid&sort=p", function() { // link to most viewed video var link = this.evaluate(function() { return document.querySelector('a.yt-uix-sessionlink.yt-uix-tile-link.spf-link.yt-ui-ellipsis.yt-ui-ellipsis-2').getAttribute('href'); }); // open the most viewed video casper.thenOpen("http://youtube.com" + link, function() { var views = this.evaluate(function() { return document.querySelector('span.watch-view-count').innerText; }); var likes = this.evaluate(function() { return document.querySelector('span.likes-count').innerText; }); var dislikes = this.evaluate(function() { return document.querySelector('span.dislikes-count').innerText; }); var date = this.evaluate(function() { return document.querySelector('span.watch-video-date').innerText; }); // doesn't work var comments = this.evaluate(function() { return document.querySelector('div.DJa').innerHTML; }); var v = ""; if (views != null ) { if (views.indexOf("views") < 0) { // if doesn't already contain word "views" v = " views"; } } var title = this.getTitle(); title = title.substring(0, title.length - 10); this.echo('Most viewed video: ' + title + " - " + views + v + "\n " + date + "\n Likes: " + likes + " Dislikes: " + dislikes + "\n Comments: " + comments + '\n'); }); }); } casper.run();DOWNLOAD
Created: February 17, 2014
Completed in full by: Michael Yaworski