You are on page 1of 1

http://www.perlmonks.org/?

node_id=74015

This is part of a script that I wrote for getting data from a password protected
site. The site uses cookies for the logins, and the password URL can be passed
straight in via the URL as GET parameters.

use LWP::UserAgent;
use HTTP::Cookies;

$ua = LWP::UserAgent->new;
$ua->cookie_jar(HTTP::Cookies->new(file => "$cookie_file",
autosave => 1));
$ua->timeout($url_timeout);
$res = $ua->request(HTTP::Request->new('GET', "$login_url"));

if ($res->is_error()) {
$response = $response->status_line;
exit;
}

$response = $ua->request(HTTP::Request->new('GET', "$data_url"));


if ($response->is_error()) {
$response = $response->status_line;
}
else {
# do what you want to do with the pages here
}

[download]
First I create a "cookie jar" which retains the cookie submitted by the site login
mechanism.. Then, I submit the login_url, which is a complete URL escaped string.
Thereafter, if the login is successful, I can navigate to any of the protected
URLs..
HTH

Answer: How can I login to get data from a webpage?


contributed by Daddio
In addition to the code sample from tinman, check out CPAN's LWP, LWP::UserAgent,
LWP::AuthenAgent.

Also, there are other nodes which may be of help here on PerlMonks that can help,
too: 1, 2, or the general UserAgent search results.

These may give you a few pointers and more examples of ways to access the sites,
whether or not the site is using cookies for login.

Answer: How can I login to get data from a webpage?


contributed by Anonymous Monk
io

You might also like