Accessing password protected web URLs from a Perl script.

planetiowa
planetiowa used Ask the Experts™
on
I'm a beginner at this but I have created simple Perl scripts to read from a web page using LWP::Simple  and LWP:UserAgent, however, I would now like to read a web page that I normally have to enter a username and password to get to.  How do I do this from a Perl script?

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
where is the username and password entered?
for some kinds of passwords you might do
perl -MLWP::Simple -e 'getprint "http://username:password@host/path"'
Top Expert 2006

Commented:
http://search.cpan.org/~gaas/libwww-perl-5.805/lwpcook.pod#ACCESS_TO_PROTECTED_DOCUMENTS


ACCESS TO PROTECTED DOCUMENTS

Documents protected by basic authorization can easily be accessed like this:

  use LWP::UserAgent;
  $ua = LWP::UserAgent->new;
  $req = HTTP::Request->new(GET => 'http://www.linpro.no/secret/');
  $req->authorization_basic('aas', 'mypassword');
  print $ua->request($req)->as_string;

Author

Commented:
I tried the first suggestion but I got errors about an unrecognized host.  On the second response using the LWP::UserAgent method, this just returns an htm page with the username and password boxes again.  This is the base page I am trying to access:
http://cp.cr-cath.pvt.k12.ia.us/
Top Expert 2006
Commented:

Author

Commented:
Thnaks for the information.  I'll have to study that for awhile but it looks promising.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial