http://www.perlmonks.org?node_id=940970

bbrelin has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I'm trying to write a small script using WWW::Scripter that will take data from a client's web site in order to automate some of their processes. The problem that I'm running into is that to access the data, I have to log on to the web site.

The web site uses a small JavaScript function to handle this. The function is:

function Login() { if(document.forms[0].login_name.value == "") { alert("Please fill in your login name"); document.forms[0].login_name.select(); return; } if(document.forms[0].login_pwd.value == "") { alert("Please fill in your password"); document.forms[0].login_pwd.select(); return; } document.forms[0].submit(); }

Using WWW::Scripter and the JavaScript plugin (and JE as the back end JS Engine) i've tried doing this:

my sourceWebSite="http://xxxxxxxx"; my $agent = WWW::Scripter->new(); my $code; $agent->use_plugin(JavaScript => engine => "JE", ); $agent->get("$sourceWebSite"); $agent->plugin('JavaScript')->set( $agent,'document','forms[0]','login_name','value'=> 'xxxxxx' ); $agent->plugin('JavaScript')->set( $agent,'document','forms[0]','login_pwd','value'=> 'xxxxxx' );

I'm trying to use the Scripter class eval method to actually run the code. I set a variable $code to contain a string which is basically the JS function listed above and then called the eval method like so.

$agent->eval($code,"JavaScript",$sourceWebSite);

This doesn't work. At least, it won't then log in and provide me with the "member" content.

Anybody got any thoughts on what I'm missing?

Thanks