source: other-projects/FileTransfer-WebSocketPair/Themes/themebuilder/bin/phantomjs-1.9.2-macosx/examples/tweets.js@ 31525

Last change on this file since 31525 was 31525, checked in by ak19, 7 years ago

Nathan provided more stuff: Themes folder contains Sencha's Themebuilder which generates GXT Themes. It includes the .theme and generated .jar files for the project theme.

File size: 1.2 KB
Line 
1// Get twitter status for given account (or for the default one, "PhantomJS")
2
3var page = require('webpage').create(),
4 system = require('system'),
5 twitterId = "PhantomJS"; //< default value
6
7// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
8page.onConsoleMessage = function(msg) {
9 console.log(msg);
10};
11
12// Print usage message, if no twitter ID is passed
13if (system.args.length < 2) {
14 console.log("Usage: tweets.js [twitter ID]");
15} else {
16 twitterId = system.args[1];
17}
18
19// Heading
20console.log("*** Latest tweets from @" + twitterId + " ***\n");
21
22// Open Twitter Mobile and, onPageLoad, do...
23page.open(encodeURI("http://mobile.twitter.com/" + twitterId), function (status) {
24 // Check for page load success
25 if (status !== "success") {
26 console.log("Unable to access network");
27 } else {
28 // Execute some DOM inspection within the page context
29 page.evaluate(function() {
30 var list = document.querySelectorAll('div.tweet-text');
31 for (var i = 0; i < list.length; ++i) {
32 console.log((i + 1) + ": " + list[i].innerText);
33 }
34 });
35 }
36 phantom.exit();
37});
Note: See TracBrowser for help on using the repository browser.