Click here to get back home

WWW::Mechanize cannot find the form.

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
WWW::Mechanize cannot find the form. dairenn 02-14-2006
Posted by dairenn on February 14, 2006, 9:04 pm
Please log in for more thread options


Can someone help me out with this error?

There is no form numbered 1 at ./regdomain.pl line 152
Died at /usr/local/lib/perl5/site_perl/5.6.1/WWW/Mechanize.pm line
1493, <STDIN> line 1.

Here is my perl script:

#!/usr/local/bin/perl -w
#
# regdomain.pl v1.00b
#
# usage:
# ./regdomain.pl filename.txt
# filename.txt contains the e-mail from sales@
# For now, this only handles registering one domain name at a time.
# For multiple domain names, or non-American registrations, you'l have
to
# go to the site yourself.
# Fortunately, those domains are pretty rare.

# Ask for the filename if not provided at the command prompt.
# As of the beta, I can't get this to work, so, we'll skip this for
now.
#
#$filename = $ARGV[0];
#
#if ($ARGV[0] =~ m/^$/) {
#        print "\n";
#        print "Enter C21 Order Text Filename\n";
#        print "(i.e., ./c21.txt): ";
#        chomp($filename = <STDIN>);
#}

# Populate hash array called ordermail with a text file...

use strict;
my %ordermail;
my $company;

while ( $_ = <> ) {
        (my $field, my $input) = split /:\s*/, $_, 2;
        my @fields = split ' ', $input;
        $ordermail = [ @fields ];
}

# Parse the hash into variables for HTML form injection...
my $firstname = "$ordermail[0]";
my $lastname = "$ordermail[1] $ordermail[2]
$ordermail[3]";
# Sometimes, they don't specify a company name, but this is mandatory.
# So, we are going to use their name as the company name if it's not
there.
if ($company =~ m/^$/) {
        $company = "$ordermail[0] $ordermail[1]
$ordermail[2] $ordermail[3]";
} else {
my $company = "$ordermail[0] $ordermail[1]
$ordermail[2] $ordermail[3] $ordermail[4]";
}
my $address = "$ordermail[0] $ordermail[1]
$ordermail[2] $ordermail[3] $ordermail[4]
$ordermail[5]";
my $city = "$ordermail[0] $ordermail[1]
$ordermail[2]";
my $state = "$ordermail[0]";
my $postalcode = "$ordermail[0]";
my $country = "$ordermail[0] $ordermail[1]";
my $phno = "$ordermail[0] $ordermail[1]
$ordermail[2]";
$phno =~ s/[^\d]//g; # Take out non-numbers
my $phone = "\+1.$phno"; # Add +1. to the number because it's required.
# A fax number is mandatory; if this is blank, we have to use all
zeros.
my $faxno = "$ordermail[0] $ordermail[1] $ordermail[2]";
$faxno =~ s/[^\d]//g;
my $fax = "\+1.$faxno";
        if ($fax =~ /\+1\.$/) {
                $fax = "\+1.0000000000";
        }
my $email = "$ordermail[0]";
my $cardtype = "Visa";
my $cardno = "4111111111111111";
# We have to split the expiry because it's two separate HTML form
fields.
my $exp = "$ordermail[0]";
my @expdate = split '/', $exp;
my $expmo = $expdate[0];
# The expiration year always needs to be four digits to match the form.
my $expy = $expdate[1];
my $expyr;
if ($expy =~ /^0/) {
        $expyr = "20$expy";
        } else {
        $expyr = $expy;
        }
my $login = "$ordermail{'CP Username'}[0]";
my $pwd = "$ordermail{'CP Password'}[0]";
my $domain = "$ordermail{'Requested Domains'}[0]";
my $regyears = "$ordermail{'Requested Domains'}[7]";
my $pdns = "ns1.idx.net";
my $sdns = "ns2.idx.net";


# Tell the operator what's going on:

print "Registering: $domain\n";
print "\n";
print "Domain Management Username: $login\n";
print "Domain Management Password: $pwd\n";
print "\n";
print "Registration Period: $regyears year(s)\n";
print "\n";
print "First Name: $firstname\n";
print "Last Name: $lastname\n";
print "Organization Name: $company\n";
print "Street Address: $address\n";
print "City: $city\n";
print "State\/Province: $state\n";
print "Postal Code: $postalcode\n";
print "Country: $country\n";
print "Telephone Number: $phone\n";
print "Fax Number: $fax\n";
print "E-Mail Address: $email\n";
print "\n";
print "Primary Name Server Hostname: $pdns\n";
print "Secondary Name Server Hostname: $sdns\n";
print "\n";
print "Using Method Type: $cardtype\n";
print "Using Card Number: $cardno\n";
print "Using Expiration Date: $expmo/$expyr\n";
print "\n";
print "OK to proceed? (Y/n): ";
chomp(my $input = <STDIN>);
if ($input =~ /^[Y]?$/i) {
        print "OK! ";
        }
        elsif ($input =~ /^[N]$/i) {
                print "Aborting as requested.\n";
                exit;
}


# HTML Form Injection:
print "Registering...\n";

#use Test::More qw(no_plan);

# Use WWW::Mechanize, initialize our robot and fetch the good form...
use WWW::Mechanize;
my $robot = WWW::Mechanize->new();
my $url =
"https://register.broadspire.com/reg/reg_system.cgi?action=bulk_order";
$robot->get($url);
die unless ($robot->success);

# Specify the Domain Management username and password...
$robot->set_visible( 0, $login, $pwd, $pwd );
$robot->click();
die unless ($robot->success);
print "Set Domain Management Username and Password.\n";

#$robot->submit_form(
#        form_number => 1,
#        fields => {
#                reg_domain => '',
#                reg_username => $login,
#                reg_password => $pwd,
#                confirm_password => $pwd
#        }
#);

$robot->submit_form(
        form_number => 1,
        fields => {
                domains => $domain,
                period => $regyears,
                owner_first_name => $firstname,
                owner_last_name => $lastname,
                owner_org_name => $company,
                owner_address1 => $address,
                owner_city => $city,
                owner_state => $state,
#                owner_country => $country, # The Default is OK
                owner_postal_code => $postalcode,
                owner_phone => $phone,
                owner_fax => $fax,
                owner_email => $email,
                fqdn1 => $pdns,
                fqdn2 => $sdns,
#                p_cc_type => $cardtype, # The Default is OK
                p_cc_num => $cardno,
#                p_cc_exp_mon => $expmo,
#                p_cc_exp_yr => $expyr,
#        },
#        select => {
#
# Commenting the below out for now, because I can't seem to get this to
work...
#
#                p_cc_exp_mon => $expmo,
#                p_cc_exp_yr => $expyr
#        },
#        tick => {
#                flag_admin_use_contact_info,
#                flag_billing_use_contact_info
#        },
#        button => "submit"
        }
);

# Order Now!
$robot->click();
$robot->success or die "Registration
failed:",$robot->response->status_line;
open (ERR, "> tmp.txt");
print ERR $robot->response->content();

# Show the domain name order number...
$robot = shift;
for my $result ( $robot->content() ) {
        print $robot->dump,"\n";
}


Here is an example of the text file to be parsed:

-----Original Message-----
From: nobody@nowhere.com
Sent: Tuesday, February 07, 2006 5:07 PM
To: Shared Account setup
Subject: Shared Web Hosting Order


Web Hosting Order

Name:                        Someone Somebody-Hypehnated
Company:
Address:                1234 Anywhere Blvd.
City:                        Somewhere
State:                        CA
Zip:                        90010
Country:                United States
Phone:                        2135551212
Fax:                        323-55-1212
Email:                        email@address.tld
Card type:                Visa
Card No.:                1234567812345678
CCID:                        000
Exp.:                        02/2010
Order Total:                60.00

Output:


CP Username:                0123456
CP Password:                owiekazowee
FTP Passwd:                ayeyiyi


Hosting Term:                12 month(s)
Requested Domains:        thedomain.com (main domain - register me please, 1
year(s))

It parses the e-mail correctly, but when it comes time to actually
registering the domain name, it fails.

Any help would be Greatly appreciated.


Thanks,
Dairenn


Similar ThreadsPosted
WWW::Mechanize "There is no Form named (...)" December 8, 2004, 5:58 am
Getting WWW::Mechanize to submit a form September 15, 2007, 3:44 pm
HTTP::Mechanize / file-form October 13, 2006, 10:16 pm
form submission automation August 13, 2006, 9:15 pm
HTML::Form, Multiple select Elements with Same name July 30, 2004, 3:48 pm
file upload, multipart form, and cgi::cache April 21, 2006, 7:01 am
Looking for AJAX HTML Table Form Module August 15, 2007, 11:29 am
HTTP::Request::Form - Problem pressing input type=image button February 1, 2005, 7:56 am
Help with Mechanize January 15, 2007, 3:14 pm
WWW::Mechanize v 1.03_01 August 3, 2004, 9:57 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap