Path: blob/master/6-Selenium/phantomjs/examples/tweets.js
164 views
// Get twitter status for given account (or for the default one, "PhantomJS")12var page = require('webpage').create(),3system = require('system'),4twitterId = "PhantomJS"; //< default value56// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")7page.onConsoleMessage = function(msg) {8console.log(msg);9};1011// Print usage message, if no twitter ID is passed12if (system.args.length < 2) {13console.log("Usage: tweets.js [twitter ID]");14} else {15twitterId = system.args[1];16}1718// Heading19console.log("*** Latest tweets from @" + twitterId + " ***\n");2021// Open Twitter Mobile and, onPageLoad, do...22page.open(encodeURI("http://mobile.twitter.com/" + twitterId), function (status) {23// Check for page load success24if (status !== "success") {25console.log("Unable to access network");26} else {27// Execute some DOM inspection within the page context28page.evaluate(function() {29var list = document.querySelectorAll('div.tweet-text');30for (var i = 0; i < list.length; ++i) {31console.log((i + 1) + ": " + list[i].innerText);32}33});34}35phantom.exit();36});373839