Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: use WWW::Mechanize or LWP to interface with WEB

by erroneousBollock (Curate)
on Nov 16, 2007 at 07:04 UTC ( [id://651131]=note: print w/replies, xml ) Need Help??


in reply to Re^2: use WWW::Mechanize or LWP to interface with WEB
in thread use WWW::Mechanize or LWP to interface with WEB

No field names, eh?

Try something like this:

use WWW::Mechanize; use strict; my $url = 'http://server/path/to/form.html'; my $mech = WWW::Mechanize->new(); $mech->get($url); die "can't get page!" unless $mech->success && $mech->content =~ /look for something/; die "can't find form!" unless $mech->form_number(0); my @values = ('learn', 'perl', [option => 'M']); die "couldn't fill out form!" unless $mech->set_visible(@values) == 3; $mech->submit; die "can't submit form!" unless $mech->success && $mech->content =~ /something useful/;

Any better?

-David

Replies are listed 'Best First'.
Re^4: use WWW::Mechanize or LWP to interface with WEB
by learnperl (Acolyte) on Nov 16, 2007 at 07:43 UTC
    Thanks David,
    Good news and not so good news, I don't get the error anymore but I nothing happens either, I had the feeling that WWW::Mechanize should fire up the web browser... Have I misunderstood...?
    One other thing, If you take look at source of $url the website has a "form tag" before the form that I want to use... in that case should be using (2)..?
    my $url = 'http://www.ancestry.com/'; my $mechObject = WWW::Mechanize->new(); $mechObject->get($url); die "can't get page!" unless $mechObject->success; die "can't find form!" unless $mechObject->form_number(0); my @values = ('learn', 'perl', [option => 'M']); die "couldn't fill out form!" unless $mechObject->set_visible(@values) == 3; $mechObject->submit; die "can't submit form!" unless $mechObject->success;
    learnperl
      $mech->form_number(0) is the first form,
      $mech->form_number(1) is the second form,
      and so on...

      Good news ... I don't get the error anymore
      Excellent.

      but I nothing happens
      Perfect!

      I had the feeling that WWW::Mechanize should fire up the web browser
      No, WWW::Mechanize acts like a web-browser, it doesn't run one.

      If you got no errors along the way (and you actually had put something useful in those two regular expressions) you can be pretty sure it worked fine.

      Update: Ah, I see you removed the regexp tests.
      Those are there to see that the resulting page "looks like" the page you expect to see. Removing those tests stops you from knowing if your truly succeeded.

      To be sure, consult the site you posted it to.

      -David.

        $mech->form_number(0) is the first form,
        $mech->form_number(1) is the second form,
        and so on...
        No, the doc says: Forms are indexed from 1, so the first form is number 1, not zero.

        Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

        yeah..haha I removed regex...
        The webpage has a login form at the top of the page... would that be form_number(0)...? I put form_number(1) and game me the previous error but when if i put the value (2) no errors similar to (0).

        After the submit I should be expecting some search results...What kind of procedure I should fallow the search results to spit out...?
        Thanks
        learnperl

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-18 04:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found