planetiowa
asked on
Accessing password protected web URLs from a Perl script.
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!
Thanks!
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_str ing;
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(
print $ua->request($req)->as_str
ASKER
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/
http://cp.cr-cath.pvt.k12.ia.us/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thnaks for the information. I'll have to study that for awhile but it looks promising.
for some kinds of passwords you might do
perl -MLWP::Simple -e 'getprint "http://username:password@host/path"'