I would like to avoid having to depend on IE for my utility I'm writing but unfortunately I can't figure out how to do the same with the WWW::Mechanize module. Does anyone know how to make the following code work under WWW::Mechanize? I've read that it doesn't support javascript so I'm not sure if it's possible or not...but with Perl I suspect it is possible somehow :)
use warnings;
use strict;
use Win32::IE::Mechanize;
my $ie;
my $id = ' 14632';
my $max_page = 9;
$ie = Win32::IE::Mechanize->new( visible => 0 );
my $url = 'http://myspace.com/Modules/ViewFriends/FriendsView.aspx?%3f
+fuseacion=user.viewfriends&friendID=' . $id;
$ie->get( $url );
sleep 1;
my $count = 0;
my $i = 0;
for (1..$max_page) {
scrape_page($_, $max_page);
}
sub scrape_page {
my ($page, $max) = @_;
print "Looking at $page ...\n";
if ($page > 1 ) {
$ie->follow_link( url => 'javascript:__doPostBack(\'ctl00$cpMain$p
+agerBottom\',\'' . $page . '\')' );
}
sleep 1;
my @data = split(/\n/, $ie->content());
foreach (@data) {
chomp;
if (/<A href=\"http:\/\/profile\.myspace\.com\/index\.cfm\?fuseact
+ion=user.viewprofile&friendid=(.*?)\">(.*?)<\/A><BR>/i) {
print "ID: $1\n";
}
}
}
Thanks
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.