arasu84 has asked for the wisdom of the Perl Monks concerning the following question:

I unable to get result page coding by using the below script. Could any one suggest to get result.

use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->get( 'http://www.crossref.org/SimpleTextQuery/' ); $mech->submit_form( form_name => 'freeTextQuery', fields => { email => 'arasu84@gmail\.com', freetext => 'Allman, J. M., Watson, K. K., Tetreault, N +. A. & ., and Hakeem, A. Y. (2005). Intuition and autism: a possible +role for Von Economo neurons. Trends in Cognitive Sciences,Cogn. Sci. + 9 (8), pp. 367-–373.', }, button => 'submitButton' ); my $result = $mech->response->content; print $result;

Replies are listed 'Best First'.
Re: unable to get response content through WWW::Mechanize
by robby_dobby (Hermit) on Jun 09, 2015 at 08:11 UTC
    Hello arasu84,

    When faced with such a situation, you may find that it's helpful to look at what the server returns as a response, by way of headers and status code. For example, since $mech->response is basically HTTP::Response, you can directly look at its status code and response line:

    my $resp = $mech->response; if($resp->is_success) { # or $mech->success # do successful stuff } else { # you have failed to get a proper response, inspect what's left of it $resp->status_line; # alternatively, if you have $resp->is_error, you may want to print ou +t the error itself: $resp->error_as_HTML; }
    HTH!
Re: unable to get response content through WWW::Mechanize
by jellisii2 (Hermit) on Jun 09, 2015 at 11:22 UTC
    You might want to check the actual form code as well. Usually these kinds of problems stem from missing inputs.