perl and html


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl and html
# 1  
Old 09-20-2005
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)?
# 2  
Old 09-20-2005
Yes. At least in principle. If the form is a GET or POST based one. Read up on LWP module for that. Some examples:

http://search.cpan.org/~gaas/libwww-...03/lwpcook.pod

Also search the Web for more examples.
# 3  
Old 09-20-2005
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\">";
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
# 4  
Old 09-20-2005
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.
# 5  
Old 09-20-2005
Quote:
Originally Posted by marcpascual
print "Content-type: text/html\n\n";
print "<base href=\"https://www.i.ph/signup_check.php\">";
print $content;
And, what are you trying to do with these code, as the <base> exists outside the following content (probably a complete HTML document)?

Quote:
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).
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.
# 6  
Old 09-21-2005
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>
# 7  
Old 09-21-2005
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Editing path in a HTML file using Perl

Hello I want to replace the path to which a hyperlink points to. I have a html file <TABLE BORDER CELLPADDING=7, border=0><TR><td>Jun-10-2013_03_19_07_AM</td><td>Ank_Insert_1</td><td><b>FAILED: 1</b></td><td><A ... (14 Replies)
Discussion started by: ankurk
14 Replies

2. UNIX for Dummies Questions & Answers

Writing an HTML file in perl

I'm writing a perl script that writes an html file. use Tie::File; my ($dir) = @ARGV; open (HTML,">","$dir/file.html") || die $!; #-----Building HTML file--------------------------- print HTML "<!DOCTYPE html> <html> <head> <title>Output</title> <link... (3 Replies)
Discussion started by: jrymer
3 Replies

3. Shell Programming and Scripting

Embedding HTML in Perl script

My webpage is hosted from perlscript(homepage.pl), i want to add piece of html code in the footer of the homepage. I simply pasted the html code at the end of the perl script as below... ======================================================== close(OUTSQL); ... (4 Replies)
Discussion started by: paventhan
4 Replies

4. Shell Programming and Scripting

HTML Encoded characters -- Perl

Hello all I have a string like " Have Fun for the rest of the day !. I will meet you tomorrow!" ! is the HTML Equivalent of ! symbol. From the above string, i would like to remove only the HTML encoded special characters. Output should be like " Have Fun for the rest of the day... (4 Replies)
Discussion started by: vasuarjula
4 Replies

5. Shell Programming and Scripting

How to put html frames in for loop in perl?

Hi, I have to insert html frames in for loop. Here is the code. for($k=0;$k<3;$k++) { print<<HTML; <html> <head> <title> HTML Horizontal Frames </title> </head> <frameset cols="25%,75%"> <frame src="a.html"> <frame src="b.html"> </frameset> (0 Replies)
Discussion started by: vanitham
0 Replies

6. Shell Programming and Scripting

Converting html to pdf perl

Hi All, I have a requirement of converting an html form into pdf using perl. The html form contains images, tables and css implementation. I tried using various perl modules but failed to achive the target. I succeeded in generating a pdf from the html file using... (2 Replies)
Discussion started by: DILEEP410
2 Replies

7. Shell Programming and Scripting

Perl + Korn + HTML

I have a perl script that prints up the html code and executes a few korn scripts to populate the web code. Disclaimer === I can throw together some korn scripts pretty quick. This code changes pretty frequently. I don't know enough about perl to do everything I need. One day maybe I'll get... (4 Replies)
Discussion started by: i9300
4 Replies

8. Shell Programming and Scripting

HTML parsing by PERL

i have a HTML report file..its in attachment(a part of the whole report is attached..name "input html.doc").also its source is attached in "report source code.txt" i just want to seperate the datas like in first line it should be.. NHTEST-3848498958-NHTEST-10.2-no-baloo a and so on for whole... (3 Replies)
Discussion started by: avik1983
3 Replies

9. Shell Programming and Scripting

Perl: Variable input via HTML

I am completely new to perl and am just going over the tutorials right now. What I am trying to attempt is to take the input from the HTML (in a form) and use those variables in a perl script. I've looked everywhere for a simple example on how to do this and cannot find it or do not understand... (5 Replies)
Discussion started by: douknownam
5 Replies
Login or Register to Ask a Question