perl and html

hi. im very new to perl. is it possible to fill up a web form and submit it using perl? example, i would like to sign up for a yahoo account though a perl script (ofcourse, granting the "type the characters as shown in imgage" is absent)?

Yes. At least in principle. If the form is a GET or POST based one. Read up on LWP module for that. Some examples:

Also search the Web for more examples.

i found some related example on the web, and i tried editing it accordign to my needs:

--
#!/usr/bin/perl -w
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent("Mozilla 8.0");
use HTTP::Request::Common qw(POST);
my $req = (POST 'https://www.i.ph/signup.php',
[ "username" => "nonsense",
"usermail" => 'myemail@yahoo.com',
"userpassword1" => "password",
"userpassword2" => "password",
"usermobile" => "639165263265",
"userchallenge" => "test test",
"useranswer" => "test",
"agreement" => 1
]);
$request = $ua->request($req);
$content = $request->content;
print "Content-type: text/html\n\n";
print "<base href=\"https://www.i.ph/signup_check.php\\"&gt;";
print $content;
exit;
--

my first problem is "agreement" above is a checkbox, im not sure how to deal with it but i did what is obvious, boolean (ofcourse im wrong, the code isnt working).

besides that, i dont know what else is wrong. im trying to make a bot to automate creation of a user so i can easily test bugs on the signup process incase some comes up. any kind of help is really appreciated. thanks

May you describe what is exactly not working? Any error messages (with line numbers and other debugging information)? And, did you try POSTing with HTTP instead of HTTPS and capture the HTTP traffic to make sure the composed HTTP message is indeed what you expect to generate before you try HTTPS? Also to use HTTPS with LWP, the SSL libraries and relevant Perl modules need to be installed. Have you installed them properly?

Without providing similar kinds of information, it is always mere guessing. There's simply too many things that can go wrong.

And, what are you trying to do with these code, as the <base> exists outside the following content (probably a complete HTML document)?

This is not a Web development forum. You can find lots of examples about HTML at places like http://www.htmlhelp.com and http://www.w3schools.com. But to ensure the checkbox will always submit a sensible value, I will always include a "value" attribute to the <INPUT type="checkbox">. Of course, there is no single standard to send the value of the checkbox control. What is more important is that the POST form you submit matches the way the form is parsed at the server side (probably PHP in your case). Your PHP may not need the value if it just checks whether the "agreement" parameter exists (i.e. isset($_POST['agreement'])) without regard to its value, or it may actually expect some value as second validation. Likewise I can't tell without seeing how your server is going to process this.

thanks for pointing me to the right direction. i was able to solve my problem with the aid of httpliveheaders. now my only problem is formatting/parsing the returned html code in a human readable format. any suggestions?

<code>
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);

my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla 8.0");
my $req = (POST 'https://www.i.ph/signup_check.php',
[ username => 'test',
useremail => 'my@email.org',
userpassword1 => 'testing',
userpassword2 => 'testing',
usermobile => 639165263265,
userchallenge => 'test',
useranswer => 'test',
agreement => 'on',
domainname => "",
'submit.x' => 49,
'submit.y' => 12
]);

my $request = $ua->request($req);
my $content = $request->content;
print $content;
exit;
</code>

What will be returned by the HTTP request actually? A complex HTML page? It depends on what is returned. For instance, if you expect a certain string to appear in the returned HTML, maybe we can just search for it. This is usually highly customized programming.

yes, a complete html page would be returned. it would be nice to search, say for example, the strings 'username' 'domainname' 'validated' on the returned html page. how would i do this?

You need all three strings to appear in the HTML?

For instance, you can do this:

@matches = ();
%u_matches = ();
while ($content =~ /(username|domainname|validated)/g) {
	push(@matches, $1);
}
foreach (@matches) {
	$u_matches{$_} = 1;
}

if ($u_matches{'validated'} && $u_matches{'username'} && $u_matches{'domainname'}) {
	print "We have all three words in the returned HTML!\n";
}