Created
March 8, 2010 05:16
-
-
Save aero/324895 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use WWW::Mechanize; | |
$|=1; | |
my ( $user, $pass ) = ( 'user_id','user_password' ); | |
my $mech = WWW::Mechanize->new(); | |
#$mech->agent_alias( 'Windows IE 6' ); | |
$mech->get('http://twitter.com/login'); | |
$mech->submit_form( | |
form_number => 2, | |
fields => { 'session[username_or_email]' => $user, | |
'session[password]' => $pass, | |
}, | |
button => 'commit', | |
); | |
die unless $mech->success; | |
my %users; | |
my $url = 'http://twitter.com/following'; | |
do { | |
$mech->get( $url ); | |
die unless $mech->success; | |
#print $mech->uri(),"\n"; | |
my $html = $mech->content(); | |
my @items = $html =~ m{<tr id="user_\d+".*?</tr>}sg; | |
foreach my $item ( @items ) { | |
my ( $info, $name ) = $item =~ m{class="(.*?)".*?<span class="label screenname">.*?title=.*?>(.*?)<}s; | |
my $is_friend = ( $info =~ m/direct-messageable/ ? 1 : 0 ); | |
print "$is_friend $name\n"; | |
$users{$name} = $is_friend; | |
} | |
} while ( $url = $mech->find_link( text_regex => qr/Next/ ) ); | |
printf "\n%d/%d Cross following rate is %2.2f%%\n", | |
scalar( grep { $users{$_} } keys %users ), | |
scalar( keys %users ), | |
100 * scalar( grep { $users{$_} } keys %users ) / scalar( keys %users ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment