On Thu, Apr 03, 2003 at 07:24:34AM -1000, Mike Clark wrote:
> I see from researching the archives of this list that people have
> succeeded in getting HTTP::Cookies to work with a login, along with
> HTML::Form.
[...]
> Maybe someone can suggest some methods to me here.
> I will be grateful for any help I can get.

Mike,

  I've started using a cookie jar recently to work on a form'd site
spider... the important thing is to use the same UserAgent object
or keep using the same cookie jar in each UserAgent->new.

  Since you didn't include a site url, I can't be certain this sample
will work on that site...

  Let me know if it works,
    Mike Simons


(cut and pasted from some other code... might not compile out of the box)

try something like this:
====
use LWP::UserAgent;
use HTTP::Cookies;
use HTML::Form;

my $cookies = HTTP::Cookies->new();
my $ua = LWP::UserAgent->new(
  timeout => 30,
  keep_alive => 10,
  cookie_jar => $cookies,
#  requests_redirectable => ['GET', 'POST', 'HEAD']
);

my $req = HTTP::Request->new(
  GET => 'http://site.com/login/page.asp'
);

my ($form);
{ # silence parse errors due to bad html
  # <input type=input ...>
  local $^W = "";

  # parse and select correct form from html
  $form = (HTML::Form->parse($res->content, $res->base))[0];
}

# parse and select correct form from html
$form = (HTML::Form->parse($res->content, $res->base))[0];

# fill in main search form
$form->value("user", "guest");
$form->value("pass", "tseug");
$form->value("foo", "bar");
$form->find_input("baz", "checkbox", 3)->value("zap");

$req = $form->click;

# post this form... 
$ua->request($req);

# you are now logged it, start spidering...

Reply via email to