follow.js: Port to use WebPage object.

1.2
Ariya Hidayat 2011-05-25 23:20:22 -07:00
parent f84bef4b38
commit 55bb382a1b
1 changed files with 25 additions and 13 deletions

View File

@ -1,7 +1,7 @@
// List following and followers from several accounts // List following and followers from several accounts
if (phantom.state.length === 0) { var page = new WebPage(),
phantom.state = ['sencha', users = ['sencha',
'aconran', 'aconran',
'ariyahidayat', 'ariyahidayat',
'darrellmeyer', 'darrellmeyer',
@ -19,19 +19,31 @@ if (phantom.state.length === 0) {
'philogb', 'philogb',
'rdougan', 'rdougan',
'tmaintz', 'tmaintz',
'whereisthysting'].join(':'); 'whereisthysting'];
phantom.open('http://mobile.twitter.com/sencha');
} else { function follow(user, callback) {
var users = phantom.state.split(':'), var page = new WebPage();
id = users[0], page.open('http://mobile.twitter.com/' + user, function (status) {
next = users[1], if (status === 'fail') {
data = document.querySelector('div.timeline-following'); console.log(user + ': ?');
phantom.state = users.slice(1).join(':'); } else {
console.log(id + ': ' + data.innerText); var data = page.evaluate(function () {
if (next) { return document.querySelector('div.timeline-following').innerText;
phantom.open('http://mobile.twitter.com/' + next); });
console.log(user + ': ' + data);
}
callback.apply();
});
}
function process() {
if (users.length > 0) {
var user = users[0];
users.splice(0, 1);
follow(user, process);
} else { } else {
phantom.exit(); phantom.exit();
} }
} }
process();