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

Hi!
I would really appreciate if somebody could advise me or show me how would one go about executing javascript code that is part of an html page using perl? I am currently using the LWP modules for doing get/post/head on html pages, but what do I do when it comes to javascripting?

Thanks,
Gaurav
  • Comment on Executing Javascript from HTML pages in perl

Replies are listed 'Best First'.
Re: Executing Javascript from HTML pages in perl
by jryan (Vicar) on Nov 06, 2002 at 22:25 UTC
    Theres a Javascript module on the CPAN that can execute JavaScript code; perhaps you can use that somehow?
(Javascript::SpiderMonkey) Re: Executing Javascript from HTML pages in perl
by PodMaster (Abbot) on Nov 07, 2002 at 06:23 UTC
    jryan is right on the money.

    I have a win32 ppm package of Javascript here

    Documentation is kind of scarce for Javascript, but you're in luck, there exists Javascript::SpiderMonkey by the same author, which is being actively maintained (see documentation).

    I'll see about putting up a ppm of Javascript::SpiderMonkey later.

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      I am running my code on linux so the Javascript::SpiderMonkey won't help. I beleve Javascript.pm has very limited funcionalitity.
        also, I found a posting...

        update (broquaint): put link in URL so as not to break the node

Re: (nrd) Executing Javascript from HTML pages in perl
by newrisedesigns (Curate) on Nov 06, 2002 at 20:48 UTC
    but what do I do when it comes to javascripting?

    Ignore it. Odds are it won't affect how you work.

    Do you have an example or something in particular in mind?

    John J Reiser
    newrisedesigns.com

      An example of a url would be https://chaseonline.chase.com/chaseonline/logon/sso_logon.jsp. If you try to do a get with LWP, it says that your browswer does not support javascript. Also, if you look a the source code, the post action is to a javascript. Similarly if you look at yahoo, the login requires it post to a javascript which in turn does a post.
Re: Executing Javascript from HTML pages in perl
by Mr. Muskrat (Canon) on Nov 06, 2002 at 20:59 UTC

    That all depends on why the javascript was included in the HTML. So take a good, long look at that javascript and ask yourself: Do I really need this? If your answer is yes, then provide the same functionality in your Perl script.

      And what if the javascript happens to be DOM manipulation (i.e. the stylesheet maninipulation I use in Text::ParagraphDiff output), or a form checker? Not everything javascript can do can be mimicked with perl.
        But in which way would that make it not possible to mimick the GET/POST requests a user agent would eventually send?

        Makeshifts last the longest.

        But who uses stylesheets or DHTML in an LWP script?

Re: Executing Javascript from HTML pages in perl
by Ananda (Pilgrim) on Nov 07, 2002 at 05:02 UTC
    What if the scripting is acheived through externas js files and also how about the External .Css files. Anandatirtha