in reply to Re: Headers and WWW::Mechanize
in thread Headers and WWW::Mechanize

Here is my code I'm testing with, but it complains that fields_ref is unknown and using fields results in another error. I'm lost...
use warnings; use strict; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $id = '14632'; my $url = "http://home.myspace.com/index.cfm?". "fuseaction=user.viewfriends&". "friendID=" . $id; $mech->get( $url ); my ($viewstate) = $mech->content =~ m/name="__VIEWSTATE".+value="([^"] ++)"/io; # print "VIEWSTATE: $viewstate\n"; # Submit an dmove to page 2 $mech->submit_form( #page => $url, form_name => 'aspnetForm', fields_ref => { '__EVENTTARGET' => 'ctl00$cpMain$pagerTop' +, '__EVENTARGUMENT' => 2, '__VIEWSTATE' => $viewstate, } ); #print $mech->content;
Any idea what I'm doing wrong?

Replies are listed 'Best First'.
Re^3: Headers and WWW::Mechanize
by Corion (Patriarch) on Jan 30, 2007 at 07:25 UTC

    As long as you don't tell us what that "other error" with using ->fields is, we can't help you. The WWW::Mechanize documentation says to use fields:

    $mech->submit_form( form_number => 3, fields => { username => 'mungo', password => 'lost-and-alone', } );

    Personally, I would set the fields in the HTML form and then simply submit the form:

    my $form = $mech->form_name('aspnetForm'); $form->value('__EVENTTARGET' => 'ctl00$cpMain$pagerTop'); ... and so on $mech->submit();
      The other error I get is: No such field '__EVENTTARGET' at test.pl line 17...
      use warnings; use strict; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $id = '14632'; my $url = "http://home.myspace.com/index.cfm?". "fuseaction=user.viewfriends&". "friendID=" . $id; $mech->get( $url ); my $form = $mech->form_name('aspnetForm'); $form->value('__EVENTTARGET' => 'ctl00$cpMain$pagerTop'); $form->value('__EVENTARGUMENT' => 2); $mech->submit(); print $mech->content;

        This error comes because WWW::Mechanize does not find a field by that name in the current form. Maybe such a field does not exist.

        Inspect your current HTML and your current form and look if they are what you think they are. Convenient methods for inspecting are:

        print $mech->content; $mech->save_content('progress.html');
        .

        Also, the documentation recommends the mech-dump utility for inspecting a page and its forms and fields.

        Have you looked at WWW::Myspace ?