Hi.
I use a hand-made function for submitting forms.
The example is only capable of POST method though.
my $tx1 = $ua->get($url);
my $tx2 = submit_form($tx1, 2, {
foo => $self->{foo},
bar => $self->{bar},
});
sub submit_form {
my ($tx, $index, $additional_params) = @_;
my $dom = $tx->res->dom->find("form")->[$index];
my %fields;
$dom->find("*[name]")->each(sub{
$fields{$_[0]->attr('name')} = $_[0]->attr('value') || '';
});
return $ua->post(
$tx->req->url->clone->path($dom->attr('action')),
form => {
%fields,
%{$additional_params || []}
}
);
}
(2014/08/20 5:23), Gunnar Strand wrote:
Hi,
I hope this is not off-topic for the list.
I am currently scraping a web page using WWW::Mechanize in a
Mojolicious::Lite application, but I am trying to convert to using the
UserAgent in a non-blocking fashion instead. In WWW::Mechanize speak, I
can say this:
$ua->submit_form(
form_number => 2,
fields => {
foo => $self->{foo},
bar => $self->{bar},
},
);
but I have been unable found any example on how to do the equivalent
with the UserAgent. All examples seem to involve knowing the form action
and specific parameters, while I would simply like to ignore everything
except some specific parameters, so that it is as loosely coupled to the
form as possible.
I assume that somehow using the $tx->res structure is the way to go, but
I haven't been able to figure it out yet. A nudge in the right direction
would be much appreciated.
BR
Gunnar
--
You received this message because you are subscribed to the Google
Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.