in reply to Different answers for script and browser (LWP)
LWP will follow the 301 so you will get the 200 from the new location. The details of the chain followed will be in previous. I have modified your code to get the Location from previous and it should do what you want. I have also added use strict and use warnings, as that is always sensible.
use strict; use warnings; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Headers; my $ua = LWP::UserAgent->new; my $hh = HTTP::Headers->new( 'User-Agents' => 'Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/201001 +01 +Firefox/21.0', Accept => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/* +;q=0.8', 'Accept-Language' => 'en-us,en;q=0.7,ru;q=0.3', 'Accept-Encoding' => 'gzip, deflate', Connection => 'keep-alive', ); $ua->default_headers( $hh ); my $cookie_jar = HTTP::Cookies->new( ); $ua->cookie_jar($cookie_jar); my @rename = ( 294 , 9806 , 9807 , ); for my $ren (@rename) { my $res = $ua->get("http://www.giftman.ru/show.php?id=$ren"); print $res->previous->header('Location')."\n"; }
Output /catalog/amulets/ /catalog/amulets/the_cult/ /catalog/amulets/aztek/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Different answers for script and browser (LWP)
by Anonymous Monk on Jun 19, 2013 at 09:02 UTC | |
|
Re^2: Different answers for script and browser (LWP)
by Sly_G (Novice) on Jun 19, 2013 at 19:08 UTC |