how to send form action?
am 27.08.2006 23:07:04 von typo3.ml
Hi! I'm using WWW::Mechanize to capture some data.
Please have a look at the html form below (I'm only showing the relevant parts);
I'm trying to get the data from the form with this:
$mech->submit_form(
fields => {
txtRateSheetID => "20000",
txtAction => "VIEW",
txtLevelTypeID => "1",
txtCategoryTypeID => "9",
txtRateSheetTypeID => "1"
});
But I'm failing to get the page I need; I guess it's because I haven't
set the action property (action=strPage , according to the
Javascript).
The question is: how do I define the action to be performed?
Thanks in advance for your comments.
Regards,
Toshiro.
------------------------------------------------------------ ----------------------------------------------
function SubmitPageWithData(strPage, RateSheetID, ActionVal,
LevelTypeID, CategoryTypeID, RateSheetTypeID)
{
//alert(RateSheetID);
//alert(ActionVal);
var form = window.document.frmMenu;
form.txtRateSheetID.value = RateSheetID;
form.txtRateSheetTypeID.value = RateSheetTypeID;
form.txtAction.value = ActionVal;
form.txtLevelTypeID.value = LevelTypeID;
form.txtCategoryTypeID.value = CategoryTypeID;
form.target = "_self";form.action=strPage;
form.method="post";
form.submit();
}
Re: how to send form action?
am 27.08.2006 23:59:52 von mumia.w.18.spam+nospam
On 08/27/2006 04:07 PM, Toshiro (mailing lists) wrote:
> [...]
> The question is: how do I define the action to be performed?
> [...]
>
Re: how to send form action?
am 28.08.2006 13:48:33 von typo3.ml
Yes, that's exactly the problem, the action is not there because the
JavaScript code assigns the action to the form (please have a look at
the Javascript code I've included in the previous message).
Unfortunately mechanize don't execute JavaScript code, so I have to
figure out the way of adding manually the data JavaScript assigns.
On 8/27/06, Mumia W. wrote:
> On 08/27/2006 04:07 PM, Toshiro (mailing lists) wrote:
> > [...]
> > The question is: how do I define the action to be performed?
> > [...]
> >
Re: how to send form action?
am 02.09.2006 19:04:44 von Peter
On Sun, 27 Aug 2006 18:07:04 -0300, Toshiro (mailing lists) wrote:
> Hi! I'm using WWW::Mechanize to capture some data.
>
> Please have a look at the html form below (I'm only showing the relevant parts);
>
> I'm trying to get the data from the form with this:
>
> $mech->submit_form(
> fields => {
> txtRateSheetID => "20000",
> txtAction => "VIEW",
> txtLevelTypeID => "1",
> txtCategoryTypeID => "9",
>
> But I'm failing to get the page I need; I guess it's because I haven't
> set the action property (action=strPage , according to the
> Javascript).
>
> The question is: how do I define the action to be performed?
Get the form object. perldoc HTML::Form. Look for action() method.
Figure out what the JavaScript would set the action to. Set it to that.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
Re: how to send form action?
am 11.09.2006 17:58:03 von typo3.ml
> > Please have a look at the html form below (I'm only showing the relevant parts);
> >
> > I'm trying to get the data from the form with this:
> >
> > $mech->submit_form(
> > fields => {
> > txtRateSheetID => "20000",
> > txtAction => "VIEW",
> > txtLevelTypeID => "1",
> > txtCategoryTypeID => "9",
> >
> > But I'm failing to get the page I need; I guess it's because I haven't
> > set the action property (action=strPage , according to the
> > Javascript).
> >
> > The question is: how do I define the action to be performed?
>
> Get the form object. perldoc HTML::Form. Look for action() method.
> Figure out what the JavaScript would set the action to. Set it to that.
>
I've been trying to do what you suggested, but I don't know how to use
Mech and HTML::Form together,
For example, the html page that has the form is the result of a previous
form that I get with Mechanize using this:
my $response = $mech->submit_form();
then I set the form value and form data with these:
my $form = HTML::Form->parse($response);
$form->action("strPage");
$form->value("txtRateSheetID", "20000");
$form->value("txtAction", "VIEW");
$form->value("txtLevelTypeID", "1");
$form->value("txtCategoryTypeID", "9");
$form->value("txtRateSheetTypeID", "1");
now, how can I retrieve the contents of this form and save it using
$mech->save_contents ?
Re: how to send form action?
am 11.09.2006 22:45:41 von peter.stevens
Hi Toshiro,
Toshiro (mailing lists) wrote:
>> Get the form object. perldoc HTML::Form. Look for action() method.
>> Figure out what the JavaScript would set the action to. Set it to that.
>>
>
There's an easier way. Get Firefox 1.5 and the TamperData plug-in
(doesn't work with the 2.0 Beta). Activate the TamperData window. Load
the desired page and submit the form. Look at the log generated by
Tamper Data. It's all there.
> I've been trying to do what you suggested, but I don't know how to use
> Mech and HTML::Form together,
>
Try the following...
$action="whatever";
# initialize other variables as appropriate....
$form = $mech->form_name($formname); # one of several methods which
return a form.
if (!$form) {
# error processing
}
$mech->field($targetField,$targetValue); # user your fieldnames and
values here...
$mech->field($usernameField,$userName);
$mech->field($passwordField,$passWord;
$form->action ( $action );
$mech->click();
The above will work if the form is already defined. Sometimes javascript
defines the form on the fly. In which case, try this:
my $f = HTML::Form->parse(<
EOT
$f->method ( "POST" ) ;
$mech->get( $homepage );
$mech->{forms} = ( $f ) ;
$mech->{form} = $f ;
$mech->submit();
Not really sure if these last few lines are kosher, but they worked ;-)
Cheers
Peter
Re: how to send form action?
am 12.09.2006 16:13:18 von Peter
On Mon, 11 Sep 2006 12:58:03 -0300, Toshiro (mailing lists) wrote:
>> > Please have a look at the html form below (I'm only showing the relevant parts);
>> >
>> > I'm trying to get the data from the form with this:
>> >
>> > $mech->submit_form(
>> > fields => {
>> > txtRateSheetID => "20000",
>> > txtAction => "VIEW",
>> > txtLevelTypeID => "1",
>> > txtCategoryTypeID => "9",
>> >
>> > But I'm failing to get the page I need; I guess it's because I haven't
>> > set the action property (action=strPage , according to the
>> > Javascript).
>> >
>> > The question is: how do I define the action to be performed?
>>
>> Get the form object. perldoc HTML::Form. Look for action() method.
>> Figure out what the JavaScript would set the action to. Set it to that.
>>
> I've been trying to do what you suggested, but I don't know how to use
> Mech and HTML::Form together,
> For example, the html page that has the form is the result of a previous
> form that I get with Mechanize using this:
>
> my $response = $mech->submit_form();
>
> then I set the form value and form data with these:
>
> my $form = HTML::Form->parse($response);
> $form->action("strPage");
Odd looking URL there, but not impossible.
> $form->value("txtRateSheetID", "20000");
> $form->value("txtAction", "VIEW");
> $form->value("txtLevelTypeID", "1");
> $form->value("txtCategoryTypeID", "9");
> $form->value("txtRateSheetTypeID", "1");
>
> now, how can I retrieve the contents of this form and save it using
> $mech->save_contents ?
my $form = $mech->form_number(1);
$mech->set_fields(txtRateSheetID => 20000, ...);
$form->action('strPage');
$mech->submit;
$mech->save_content($filename);
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/