Hi, I'm new to Perl. Please take it easy on me.

I want to automatically login and download a Document from a university Platform, using WWW::Mechanize. The login seems to work, but after that I am not able to call any methods on my mechanize Object (I test this with ->title). I know that the site directly redirects after the login. Is this why the object is "broken"? Do I have to somehow deal with the redirect?

#!/usr/bin/perl use warnings; use strict; use LWP::Simple; use WWW::Mechanize; my $derp = WWW::Mechanize->new(); my $url = "myurl"; $derp -> cookie_jar(HTTP::Cookies->new()); $derp -> get($url); $derp -> content(); $derp -> follow_link(text=>"loginLink"); print $derp -> title(), "\n"; my @forms = $derp -> forms(); foreach (@forms) { my @input_fields = $_->param; print "form params are:\n"; foreach (@input_fields) { print "$_\n"; } } print "filling in form..\n"; $derp -> field("j_username", "user"); $derp -> field("j_password", "password"); $derp -> submit(); if($derp -> success()) { print "success\n"; } else { print "something went wrong\n"; } print $derp -> title(), "\n";

The output is success, but I get the following error: Use of uninitialized value in print at messing_around.plx line 43. I think that submit() returns something crap. Is this because I made a mistake or because of the redirect I should somehow deal with?


In reply to Mechanize login, but redirect. [SOLVED] by scarfguy

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.