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

Hi all!

Im writing a spider using WWW::Mechanize, and ive found a web with a login box out of a <form> tag. <input type's> are not inside any form, and WWW::Mechanize says:

<input> outside <form> at /usr/lib/perl5/site_perl/5.8.3/WWW/Mechanize.pm line 1335

Is there any way of filling this boxes (are username and password), and hit the submit button?

Thank you!

Retitled by davido.

  • Comment on WWW::Mechanize and text input outside form

Replies are listed 'Best First'.
Re: WWW::Mechanize and text input outside form
by PodMaster (Abbot) on Jan 05, 2005 at 18:46 UTC
    Yes, but not by using ->value() because that (<input> outside of <form>) is not valid html. You would need to use ->request().

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: WWW::Mechanize and text input outside form
by Corion (Patriarch) on Jan 05, 2005 at 18:40 UTC

    No. Or rather, in principle yes, but it won't work as you want it to work, as input fields outside of form tags will never be submitted by the browser, except via Javascript. And WWW::Mechanize does not understand Javascript.

      Although you could rewrite the HTML so that the input field was inside the form tags...

      # untested; salt to taste my $html = $mech->content; $html =~ s/(<input[^>]+>)(.*?<form[^>]*>)/$2$1/; $mech->update_html($html);

          --k.