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

Re^2: URL Redirect

by hippo (Bishop)
on Sep 06, 2016 at 11:37 UTC ( [id://1171241]=note: print w/replies, xml ) Need Help??


in reply to Re: URL Redirect
in thread URL Redirect

Here is a simplified script which prints the first redirect of a URL (because in the absense of any statement to the contrary this is what I think you are asking for).

#!/usr/bin/env perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $src = 'http://google.com/'; my $res = $ua->get($src); my ($redirect) = $res->redirects; if (defined $redirect) { print "$src redirects to " . $redirect->header('Location') . "\n"; } else { print "$src has no redirect. It returned: " . $res->status_line . +"\n"; }

I've used Google as the source because it works whereas your provided source has issues (which you could take up with them). I think that this is pretty clear and shows how the various methods may be used to obtain information of relevance to the programmer. Do read the documentation of the modules you are using.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-24 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found