I run into this a lot.  There is JavaScript in the page, and you need to
emulate that in your script.

Look at the source HTML for the page.  It takes the password and look like
it Base 64 encodes the password, then sets a hidden form field named
"encoded_pw" to the value.  It then clears the password field before sending
the data.

You need to emulate this process in your script.  After that I would think
it would work.

Rob

-----Original Message-----
From: Pablo Fischer [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 02, 2003 5:17 PM
To: [EMAIL PROTECTED]
Subject: WWW::Mechanize and Cookies


Hi!

Im creating an script that checks for broken links. Im using this modules:

use WWW::Mechanize;
use HTTP::Cookies;

What Im trying to do?, I need to login in a website (cause to check broken 
links I need to be loged). 

I also checked the cookies once I've loged and they're created, however,
when 
I try to entrer another website I cant cause the website shows me a pretty 
message: "Not Authorized".

My Code:
____________________
#El archivo en el que se guardan las cookies
$cookies = "/home/unmada/cookies.txt";

#El objeto que va a estar escuchando las cookies
$cookie = HTTP::Cookies->new(
                             file => $cookies,
                             ignore_discard => 1,
                             autosave => 1);
#$agent->cookie_jar($cookie);

#El objeto que va a hacerla de navegador
my $agent = WWW::Mechanize->new(agent => 'Mozilla/5.0',
                                debug => 1);
#La dirección que se va a visitar (la primera)
my $url = "http://cursos.itesm.mx/webapps/login";;

#$agent->redirect_ok();
#Decirle al navegador que las cookies van a ser guardadas en el objeto
cookie
$agent->cookie_jar($cookie);

#Cargamos la página
$agent->get($url);
#Mostramos el titulo de la página
print $agent->title(),"\n";
#Buscamos el formulario que tiene el nombre de 'login'
$agent->form("login");
#Llenamos el campo de user_id
$agent->field("user_id", "username");
#Llenamos el campo de password
$agent->field("password", "password");
#Le damos ENTER
$agent->submit();

Then to enter another website (in the same domain), I jsut:

$agent->get("otherurl_of_the_same_domain");
____

Thanks!
Pablo
-- 
Pablo Fischer Sandoval ([EMAIL PROTECTED])
http://www.pablo.com.mx
http://www.debianmexico.org
GPG FingerTip: 3D49 4CB8 8951 F2CA 8131  AF7C D1B9 1FB9 6B11 810C
Firma URL: http://www.pablo.com.mx/firmagpg.txt

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to