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

Hi,
I wrote the following script for posting a query to a server (like search engine) and fetch the response(result page).
use LWP::UserAgent; $ua = LWP::UserAgent->new; $ua->agent('Mozilla/4.0'); use HTTP::Request::Common qw(POST); push @{ $ua->requests_redirectable }, 'POST'; #change default setting my $req = POST( 'http://some.com', Content_Type => 'multipart/form-data' , Content => [ para1=> "value"]); $response = $ua->request($req);
The server should direct me to a 'middle' page first and wait for a while (around half min)for processing the search. Then, that middle page would redirect to another page (that's what I want to get).

However, I just fetched the middle page. I checked the redirection function, and used print $response->is_redirect; but no value was printed out.

Does anything go wrong?

Replies are listed 'Best First'.
Re: Redirection doesn't work?
by sauoq (Abbot) on Sep 27, 2005 at 09:00 UTC

    The redirection from the "middle" page is probably done via a meta tag. If the URL never changes, then wait a bit on your own and request it. If the URL does change, you'll probably need to parse it out of the "middle" page's source.

    -sauoq
    "My two cents aren't worth a dime.";
    
      Thx!

      I just check the source code, the "middle" page is done via a meta tag. So, dose it mean that the "middle" page can't be redirected automatically?

      I tried to use  timeout to extend the exceuting time, but the request stopped before times up(or before finish the search so give me a "middle" page). Does it due to meta tag?

      The final page has a different URL than the "middle" page. The only way to fetch the result page is parse out of the "middle" page,right? Any other methods??
        So, dose it mean that the "middle" page can't be redirected automatically?

        It probably means that you will have to write to write the code to automate it. (Of course, someone could still pop up and say, "no, wait; there's a module for that on CPAN." I don't know of one though.)

        The final page has a different URL than the "middle" page. The only way to fetch the result page is parse out of the "middle" page,right? Any other methods??

        If the URL of the final page is subject to change and the only place to get it is from the "middle" page, then yes, you'll have to parse it out. But at least it shouldn't be particularly hard to do. You might want to be sure the URL actually does change before going to the trouble though. If it is the same across requests, then there's probably no need for you to look at the middle page at all.

        -sauoq
        "My two cents aren't worth a dime.";