Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I have a script that reads one of my pages to test it. the page it tests, will redirect to a number of different urls.

I use LWP to contact the page and get me the html of the page it loads. Some of them are identical source code.

I need to know what URL it is redirecting to.
How can I get that from LWP?

Here is my code:

my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/8.0"); $ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt", autosave => 1)); push @{$ua->requests_redirectable}, 'GET'; my $req = HTTP::Request->new(GET => "$_fileLoc"); $req->referer($_fileLoc); # Pass request to the user agent and get a response back $res = $ua->request($req); print $res->status_line, "\n"; if($res->status_line =~ /404 Not Found/i) { $_bad++; } else { if($res->is_success) { print $res->is_success, "\n"; if($res->status_line =~ /404 Not Found/i) { $_bad++; } else { $_cn = $res->content; print $_cn, "\n"; } } else { $_bad1++; $_errorT = $res->status_line; print qq~error: "~ . $_errorT . '"'. \t;#' } }
that is a section of my code.
How can I get this to only tell me the URL it redirected to? not the url it ended up on, but where it redirected to, like this: header("Location: http://mydomain.com/path1/someotherpath.php"); have it give me the redirected url: http://mydomain.com/path1/someotherpath.php, because someotherpath.php would also redirect to one other location, so I need the first one.

Can someone tell me how to do this?

Thank you.

Richard

In reply to LWP Question by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (8)
    As of 2014-12-21 10:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (104 votes), past polls