Sha256: 34d7d4ba7344fdb99f9bab4feb3e765856d38b0a61641143e4ea70a34bce3700

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

// Get twitter status for given account (or for the default one, "HeadlessPhantom")

var page = require('webpage').create(),
    system = require('system'),
    twitterId = "HeadlessPhantom"; //< 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 (system.args.length < 2) {
    console.log("Usage: tweets.js [twitter ID]");
} else {
    twitterId = system.args[1];
}

// 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, ''));
            }
        });
    }
    phantom.exit();
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
phantomjs.rb-0.0.2 vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.js
phantomjs.rb-0.0.1 vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.js