in reply to Re: LWP multi-form POST
in thread LWP multi-form POST

A lot of sites use javascript to submit multiple forms. This allows all sorts of things, including creating hoops that make it harder to use a language like perl to spider a site.

Want to support the EFF and FSF by buying cool stuff? Click here.

Replies are listed 'Best First'.
Re: LWP multi-form POST
by jonadab (Parson) on Feb 10, 2004 at 22:44 UTC
    A lot of sites use javascript to submit multiple forms

    Can you site an example of a site that does this? (I'm not denying it -- I've seen all sorts of weird things done with scripts that ought not to be possible. I'm just curious how it's accomplished, given that normally the submission of a form causes the browser to stop executing the scripts on that page as it goes on to fetch the new form-result page.)

    This allows all sorts of things, including creating hoops that make it harder to use a language like perl to spider a site.

    I suspect it's possible to get around this using WWW::Mechanize and maybe Clone::PP, but I'd have to see the details of what the scripts on the site are doing.


    $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

      A lot of sites use javascript to submit multiple forms

      Can you site an example of a site that does this? (I'm not denying it -- I've seen all sorts of weird things done with scripts that ought not to be possible. I'm just curious how it's accomplished, given that normally the submission of a form causes the browser to stop executing the scripts on that page as it goes on to fetch the new form-result page.)

      Basically, if you use a <form NAME="foo"> tag in the forms declaration you can use:

      document.foo.submit();

      To submit a form. Most of the time this is used to create hyperlinks which submit a form, or forms that submit themselves if you click on a select box, for instance. However, it can be extended by creating a class of functions to submit multiple forms at the same time. I don't have any examples off the top of my head, but if I come across one I will be sure to post it.


      Want to support the EFF and FSF by buying cool stuff? Click here.
        document.foo.submit();

        Yeah, that much I'm familiar with; I've personally seen examples of sites that use scripts to submit forms. This is no problem for scripting, because instead of executing the script you just submit the form. Sometimes the script does some other things before it submits the form, such as changes some field values. In that case, you just do that first, then submit the form.

        However, it can be extended by creating a class of functions to submit multiple forms at the same time.

        That's what I haven't seen and wouldn't know how to do. (How do you stop your script from ceasing to execute when the first form is submitted? Or is Javascript multithreaded these days? Where do the extra result pages go, then? Do they pop up in extra windows, or what?) Anyway, that's some pretty weird stuff, submitting multiple forms at once. Sites ought not to do such things. Sometimes I wish LiveScript had never been developed.


        $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/