Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Mechanize Cannot Detect Forms

by Anonymous Monk
on Jun 27, 2011 at 23:18 UTC ( [id://911623]=perlquestion: print w/replies, xml ) Need Help??

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

I'm using WWW::Mechanize version 1.66. When I do this,
$ mech-dump url
this shows 3 forms. But when I try to run this code,
use strict; use Data::Dumper; use WWW::Mechanize; my $m = WWW::Mechanize->new( autocheck => 1 ); $m->agent_alias( 'Windows Mozilla' ); $m->cookie_jar( HTTP::Cookies->new ); $m->get( 'same_url_as_mech-dump' ); print Dumper ( $m->forms() ); $m->submit_form( form_number => 1, fields => $fields );
Here's the output.
There is no form numbered 1 ...
Also, there is no output from $m->forms(). This is weird because mech-dump was able to find the forms. Any help?

Replies are listed 'Best First'.
Re: Mechanize Cannot Detect Forms
by roboticus (Chancellor) on Jun 27, 2011 at 23:56 UTC

    Some websites do different things for different clients. I don't know what agent mech-dump is using, but it lets you specify it, so try telling it the same agent as the one in your script, like:

    $ mech-dump --agent-alias='Windows Mozilla' url

    Note: I don't work on HTML/HTTP applications...

    Update: I notice that you put single quotes inside your $m->get() call. You're not putting a variable in single quotes there, did you?

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Mechanize Cannot Detect Forms
by Marshall (Canon) on Jun 28, 2011 at 00:04 UTC
    I would leave off this: agent_alias( 'Windows Mozilla' ) and use the default. I am not sure that this string without version info would be recognized as a known browser. When I am pretending to be something too stupid to know Java, I use: $ua->agent("Mozilla/4.76 [en] (Windows NT 5.0; U)"); You can definitely get different results depending upon what kind of browser you claim to be (this is not always the case, but it does happen).
Re: Mechanize Cannot Detect Forms
by ajose (Acolyte) on Jun 28, 2011 at 12:53 UTC
    Are you getting any output while dumping the forms using print Dumper ( $m->forms() );?

    If this step works fine, try to select the form only with the form number by discarding fields parameter.

Re: Mechanize Cannot Detect Forms
by Anonymous Monk on Jun 28, 2011 at 07:06 UTC

    Any help?

    Turn on debugging and compare the http mech-dump sends, to what your program sends

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://911623]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-23 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found