programingnoob
Technical User
Hi,
I got thsi script on the net, and I don't know how to get this working, as I do not understand it at all, can someone please teach me what the script is doing?
[script]
## PERL modules that mimick the browser and the URL
require LWP;
require URI::URL;
use strict;
use CGI; ## PERL module to read HTML form values (not used in this version of the script)
my($hdr,$server_response);
## The URL location of the HTML form
my($statement_URL)="
## Create a new CGI object
my($query)=new CGI;
## Right now the values are hard-coded
$hdr="index=books&field-keywords=kampf&rank=+amzrank&Go.x=6&Go.y=6";
## "call" the HTML form with the above name=value pairs
$server_response=&browse($statement_URL,$hdr); ## Fire the URL
## Print the MIME header
print "Content-type: text/html\n\n";
## Print the output from the HTML form.
print "$server_response";
## Subroutine that does all the actual work
sub browse(){
my($statement_URL,$hdr)=@_;
my($content_type,$method);
## MIME type for the HTML form
$content_type="application/x-$method="POST"; ## The method of submitting the FORM (<FORM method=post....>)
## Create the HTTP header that we want to sent to the web server where the form is located
my($headers)= new HTTP::Headers
'Content-Type' => $content_type,
'MIME-Version' => '1.0',
'Date' => HTTP:
ate::time2str(time),
'Accept' => 'text/html';
my($ua)= new LWP::UserAgent;
## Mimick the Netscape browser ver 4.7
$ua->agent("Mozilla/4.7 [en] (WinNT; U)"
; # Define env variable - HTTP_USER_AGENT
## Create a new URL obejct
my($url)= new URI::URL($statement_URL);
## Send the HTTP request to the web server
my($request)= new HTTP::Request($method, $url, $headers,$hdr);
## gather the response from the web server. (results of the HTML form submission)
my($response)= $ua->request($request);
my($reply);
if ($response->is_success){ ## All is ok
$reply=$response->content; ## send the HTML output
}else{
$reply=$response->error_as_HTML(); ## send the error
}
return $reply;
}
[/script]
Even though this script is heavily commented , I got lost in the early part.
Please teach me,
Thanks!
I got thsi script on the net, and I don't know how to get this working, as I do not understand it at all, can someone please teach me what the script is doing?
[script]
## PERL modules that mimick the browser and the URL
require LWP;
require URI::URL;
use strict;
use CGI; ## PERL module to read HTML form values (not used in this version of the script)
my($hdr,$server_response);
## The URL location of the HTML form
my($statement_URL)="
## Create a new CGI object
my($query)=new CGI;
## Right now the values are hard-coded
$hdr="index=books&field-keywords=kampf&rank=+amzrank&Go.x=6&Go.y=6";
## "call" the HTML form with the above name=value pairs
$server_response=&browse($statement_URL,$hdr); ## Fire the URL
## Print the MIME header
print "Content-type: text/html\n\n";
## Print the output from the HTML form.
print "$server_response";
## Subroutine that does all the actual work
sub browse(){
my($statement_URL,$hdr)=@_;
my($content_type,$method);
## MIME type for the HTML form
$content_type="application/x-$method="POST"; ## The method of submitting the FORM (<FORM method=post....>)
## Create the HTTP header that we want to sent to the web server where the form is located
my($headers)= new HTTP::Headers
'Content-Type' => $content_type,
'MIME-Version' => '1.0',
'Date' => HTTP:
'Accept' => 'text/html';
my($ua)= new LWP::UserAgent;
## Mimick the Netscape browser ver 4.7
$ua->agent("Mozilla/4.7 [en] (WinNT; U)"
## Create a new URL obejct
my($url)= new URI::URL($statement_URL);
## Send the HTTP request to the web server
my($request)= new HTTP::Request($method, $url, $headers,$hdr);
## gather the response from the web server. (results of the HTML form submission)
my($response)= $ua->request($request);
my($reply);
if ($response->is_success){ ## All is ok
$reply=$response->content; ## send the HTML output
}else{
$reply=$response->error_as_HTML(); ## send the error
}
return $reply;
}
[/script]
Even though this script is heavily commented , I got lost in the early part.
Please teach me,
Thanks!