Subject: | RE: friends_from_profile only returns the first page of results |
Date: | Tue, 22 Apr 2008 01:53:40 +0200 |
To: | <bug-www-myspace [...] rt.cpan.org>, <grantg [...] cpan.org> |
From: | THEARTOFWEB <theartofweb [...] hotmail.com> |
I have just come up with something to get all friends, it works great yet it takes a lot to get, say, 100000 friend ids:
#!/usr/bin/perl
use strict;
use warnings;
my $total_pages = $friend_id_has_x_friends / 40;
my $friend_id = 12345;
my @friendids = &_get_all_friends( $friend_id, $total_pages );
sub _get_all_friends ($$)
{
use LWP::UserAgent;
my $friend_id = shift;
my $total_pages = shift;
foreach my $page ( 1 .. $total_pages )
{
my $ua = LWP::UserAgent->new;
$ua->agent('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)');
my $url = 'http://friends.myspace.com:80/index.cfm?fuseaction=user.viewfriends2&friendID=' . $friend_id . '&p=' . $page;
my $res = $ua->get($url);
my $html;
my @friendids;
if ($res->is_success)
{
$html = $res->content;
} else {
die $res->status_line;
}
while ( $html =~ //g )
{
push @friendids,$1;
}
}
my %uniq;
my @newfriendids = grep { $uniq{$_}++ == 0 } @friendids;
return @newfriendids;
}
__END__;
so, how about that?
Show quoted text
_________________________________________________________________
Racconta le tue emozioni sul blog!
http://home.services.spaces.live.com/