WWW::Mechanize cannot find the form.

WWW::Mechanize cannot find the form.

am 15.02.2006 03:04:36 von dairenn

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, 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 = );
#}

# 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{$field} = [ @fields ];
}

# Parse the hash into variables for HTML form injection...
my $firstname = "$ordermail{Name}[0]";
my $lastname = "$ordermail{Name}[1] $ordermail{Name}[2]
$ordermail{Name}[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{Name}[0] $ordermail{Name}[1]
$ordermail{Name}[2] $ordermail{Name}[3]";
} else {
my $company = "$ordermail{Company}[0] $ordermail{Company}[1]
$ordermail{Company}[2] $ordermail{Company}[3] $ordermail{Company}[4]";
}
my $address = "$ordermail{Address}[0] $ordermail{Address}[1]
$ordermail{Address}[2] $ordermail{Address}[3] $ordermail{Address}[4]
$ordermail{Address}[5]";
my $city = "$ordermail{City}[0] $ordermail{City}[1]
$ordermail{City}[2]";
my $state = "$ordermail{State}[0]";
my $postalcode = "$ordermail{Zip}[0]";
my $country = "$ordermail{Country}[0] $ordermail{Country}[1]";
my $phno = "$ordermail{Phone}[0] $ordermail{Phone}[1]
$ordermail{Phone}[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{Fax}[0] $ordermail{Fax}[1] $ordermail{Fax}[2]";
$faxno =~ s/[^\d]//g;
my $fax = "\+1.$faxno";
if ($fax =~ /\+1\.$/) {
$fax = "\+1.0000000000";
}
my $email = "$ordermail{Email}[0]";
my $cardtype = "Visa";
my $cardno = "4111111111111111";
# We have to split the expiry because it's two separate HTML form
fields.
my $exp = "$ordermail{'Exp.'}[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 = );
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=b ulk_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