in reply to Re: Passing Values to a webpage and retrieving an answer
in thread Passing Values to a webpage and retrieving an answer

I tried using www:Mechanize to do it (after searching the web). What i have so far is:

my $ua = LWP::UserAgent->new; $ua->env_proxy; $te='hallo hallo hallo'; print $te; my $response = $ua->get('http://sentimentanalyzer.appspot.com','in +put'=>$te); if ($response->is_success) { #In here i want to retrieve a value from the site after # inserting the text and hitting the "submit" button. }

The textarea in the site is named "input".

I also didn't figure out how to activate the button..

Replies are listed 'Best First'.
Re^3: Passing Values to a webpage and retrieving an answer
by Corion (Patriarch) on Apr 30, 2012 at 22:21 UTC

    So, where in that script do you use WWW::Mechanize?

    Also, again, please do post a complete script, together with the output you get and the output you expect. The script you posted above does not run, because it does not load any of the needed modules.

      My mistake, didn't use Mechanize.

      My code is -

      require HTTP::Request; require LWP::UserAgent; use HTTP::Request::Common; print "hallo\n"; my $ua = LWP::UserAgent->new; $ua->env_proxy; $te='hallo hallo hallo'; print $te; my $response = $ua->get('http://sentimentanalyzer.appspot.com','in +put'=>$te); if ($response->is_success) { print "seccess\n"; $page=$response->content; print $page; }

      I wanted to print the content of the response to see what i am getting but it was the original url HTML code. I can't pass the text to the text area or activate the button (at least it doesn't show in the response content). How can i make it work and get a specific value from it?

        If you want to behave like a browser, I recommend using WWW::Mechanize. Otherwise, you will have to know what the target page for the form action is, and whether it takes a GET request or a POST request. Then you have to create the POST requests yourself. See HTTP::Request::Common, and use it.

        Usually, WWW::Mechanize takes care of all those steps for you, which is why I prefer it.