Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Different answers for script and browser (LWP)

by rnewsham (Curate)
on Jun 18, 2013 at 21:39 UTC ( [id://1039671]=note: print w/replies, xml ) Need Help??


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
    Alternatively, there is $ua->simple_request() which does not redirect.
Re^2: Different answers for script and browser (LWP)
by Sly_G (Novice) on Jun 19, 2013 at 19:08 UTC
    Wow, thanks a lot! I wouldn't get to it by myself.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1039671]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-19 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found