use strict; use warnings; use WWW::Mechanize; use HTTP::Cookies; use Data::Dumper; my $url = 'http://search.cpan.org'; my $searchstring = 'mechanize'; my $mech_obj = WWW::Mechanize->new(); $mech_obj->get( $url ); if( not $mech_obj->success() ) { print "Could not retrieve page:\n"; print $mech_obj->content(); die; } print "all forms:\n", Dumper( [ $mech_obj->forms ] ); $mech_obj->form_number( 1 ); $mech_obj->field( 'query' => $searchstring ); print "current form:\n", Dumper( $mech_obj->current_form() ); $mech_obj->submit(); print "content:\n", $mech_obj->content(); #### all forms: $VAR1 = [ bless( { 'inputs' => [ bless( { 'value' => '', 'size' => '35', 'type' => 'text', 'name' => 'query' }, 'HTML::Form::TextInput' ), bless( { 'seen' => [ 1, 0, 0, 0 ], 'menu' => [ 'all', 'module', 'dist', 'author' ], 'current' => 0, 'type' => 'option', 'name' => 'mode' }, 'HTML::Form::ListInput' ), bless( { 'value' => 'CPAN Search', 'type' => 'submit' }, 'HTML::Form::SubmitInput' ) ], 'extra_attr' => { 'class' => 'searchbox', 'name' => 'f' }, 'enctype' => 'application/x-www-form-urlencoded', 'method' => 'GET', 'action' => bless( do{\(my $o = 'http://search.cpan.org/search')}, 'URI::http' ) }, 'HTML::Form' ) ]; current form: $VAR1 = bless( { 'inputs' => [ bless( { 'value' => 'mechanize', 'size' => '35', 'type' => 'text', 'name' => 'query' }, 'HTML::Form::TextInput' ), bless( { 'seen' => [ 1, 0, 0, 0 ], 'menu' => [ 'all', 'module', 'dist', 'author' ], 'current' => 0, 'type' => 'option', 'name' => 'mode' }, 'HTML::Form::ListInput' ), bless( { 'value' => 'CPAN Search', 'type' => 'submit' }, 'HTML::Form::SubmitInput' ) ], 'extra_attr' => { 'class' => 'searchbox', 'name' => 'f' }, 'enctype' => 'application/x-www-form-urlencoded', 'method' => 'GET', 'action' => bless( do{\(my $o = 'http://search.cpan.org/search')}, 'URI::http' ) }, 'HTML::Form' ); Unexpected field value http://search.cpan.org at (eval 5) line 1