I'm trying to get a little more familiar with the WWW::Mechanize module and have the following situation...I'm able to get a specific URL, but I'm trying to click a link on the page that uses javascript behind the scenes and two hidden fields. I'm able to get the required data for the two hidden fields but cannot submit the form for some reason. Can anyone tell me what I'm doing wrong?
This is the script I'm using
use strict;
use warnings;
use WWW::Mechanize;
use Data::Dumper;
my $mech = WWW::Mechanize->new();
my $url = 'http://myspace.com/Modules/ViewFriends/FriendsView.aspx?%3f
+fuseacion=user.viewfriends&friendID=' . 16193600;
$mech->get( $url );
#print $mech->content();
# my $links = $mech->find_all_links();
# print Dumper($links);
my $next_link = $mech->find_link( text_regex => qr/Next/i );
if($next_link) {
my $url = $next_link->url();
if($url =~ /javascript:__doPostBack\('(.*)','(.*)'\)/) {
my $target = $1;
print "TARGET: $target\n";
my $argument = $2;
print "ARGUMENT: $argument\n";
$mech->submit_form( {
form_name => 'aspnetForm',
fields_ref => {
'__EVENTTARGET' => $target,
'__EVENTARGUMENT' => $argument,
},
} ) }
}
else {
print "no more links on page\n";
}
Thanks for the help :)
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.