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

In reply to How do I call a JavaScript function from WWW::Scripter? by bbrelin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.