For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > December 2007 > Mechanize::How do I get the results back after Submitting a Form.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Mechanize::How do I get the results back after Submitting a Form.
newBee

2007-12-08, 10:05 pm

Hello All,

I have been having trouble figuring out Mechanize module specially on
getting back the results after submitting a form. I am trying to
access ancestry dot com to get the results according to the the form
that I submit. Fallowing code is written to fill the First Name input
field and Last Name Input Filed and submit.

I went through great trouble figuring out some section since ancestry
dot com site doesn't name their input fields. But according to the
below code segment I only get spitted out html version of the first
page of the ancestry dot com whereas I would like to see the results
according to the first and last name that I submit.

Currently I am just trying to figure out on getting the results back.
Once I get pass this, I will be using some of the functions that I
have created to fill the first and the last name instead of passing
the plain first and last name.

#!/usr/bin/perl

use Text::Soundex;
use WWW::Mechanize;
#use MakeRegex;
$DEBUG = true;
$SOUNDEX = 0;

print STDOUT "\nEnter First name: ";
$firstname = <STDIN>;
chomp $firstname;

print STDOUT "\nEnter Last name: ";
$lastname = <STDIN>;
chomp $lastname;

my $url = 'http://www.ancestry.com/';
my $mechObject = WWW::Mechanize->new();

$mechObject->get($url);
die "can't get page!"
unless $mechObject->success &&
$mechObject->content =~ /Your First Name/i;

die "can't find form!"
unless $mechObject->form_number(2);

my @values = ($firstname, $lastname, [option => 'M']);
die "couldn't fill out form!"
unless $mechObject->set_visible(@values) == 3;

$mechObject->submit;
die "can't submit form!"
unless $mechObject->success &&
$mechObject->content =~ /Your Last Name/i;

It will be a great help if someone could give some audience on this.

Thanks, Anu

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com