2011-06-01 17:18:08 +04:00
|
|
|
// Get twitter status for given account (or for the default one, "sencha")
|
2010-12-27 10:46:50 +03:00
|
|
|
|
2011-06-01 17:18:08 +04:00
|
|
|
var page = new WebPage(),
|
|
|
|
twitterId = "sencha"; //< default value
|
|
|
|
|
|
|
|
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
|
|
|
page.onConsoleMessage = function(msg) {
|
|
|
|
console.log(msg);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Print usage message, if no twitter ID is passed
|
|
|
|
if (phantom.args.length < 1) {
|
|
|
|
console.log("Usage: tweets.js [twitter ID]");
|
2010-12-27 10:46:50 +03:00
|
|
|
} else {
|
2011-06-01 17:18:08 +04:00
|
|
|
twitterId = phantom.args[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Heading
|
|
|
|
console.log("*** Latest tweets from @" + twitterId + " ***\n");
|
|
|
|
|
|
|
|
// Open Twitter Mobile and, onPageLoad, do...
|
|
|
|
page.open(encodeURI("http://mobile.twitter.com/" + twitterId), function (status) {
|
|
|
|
// Check for page load success
|
|
|
|
if (status !== "success") {
|
|
|
|
console.log("Unable to access network");
|
|
|
|
} else {
|
|
|
|
// Execute some DOM inspection within the page context
|
|
|
|
page.evaluate(function() {
|
|
|
|
var list = document.querySelectorAll('span.status');
|
|
|
|
for (var i = 0; i < list.length; ++i) {
|
|
|
|
console.log((i + 1) + ": " + list[i].innerHTML.replace(/<.*?>/g, ''));
|
|
|
|
}
|
|
|
|
});
|
2010-12-27 10:46:50 +03:00
|
|
|
}
|
|
|
|
phantom.exit();
|
2011-06-01 17:18:08 +04:00
|
|
|
});
|