I've just written a script that retrieves information from 'bookplace.co.uk',and prints out the search results!! This website uses "POST" to retract its information. What i wanted to do was, get information from a website that uses "GET" eg. 'bol.com', how do i go on about it? Below is the script that searches bookplace.co.uk.
------------------------------------------------------------
#!usr/local/bin/perl use CGI; use LWP; use LWP::UserAgent; use HTML::Parse; use HTML::FormatText; use strict; #turn on more error checking use CGI::Carp qw(fatalsToBrowser set_message); BEGIN { sub handle_errors { my $msg = shift; print "Oh Gosh!!"; print "Got an error: $msg"; } set_message(\&handle_errors); } #use CGI::Carp qw(fatalsToBrowser); #GLOBAL VARIABLES my @book; #array storing all books my @pairs; #variables storing information on a single book my $book; my $price; my $format; my $publisher; my $pub_date; my $req; my $isbn; my $buffer; my $titleValue; my $name; my $value; my $title; #END OF GLOBAL VARIABLES read ( STDIN, $buffer, $ENV{CONTENT_LENGTH} ); @pairs = split ( /&/, $buffer ); foreach $titleValue(@pairs) { ($name, $value) = split(/=/, $titleValue); $value =~ tr/+/ /; $title = $value; } #$title = 'Java'; my $url = "http://www.bookplace.co.uk/bookplace/results.asp?SEARCH_FIE +LD=KEYWORD&TAG=BHSLFX8X99X97X163DLT9W&CID=&SEARCH_TEXT=$title&FORM_OB +=%24RANK&x=23&y=14"; # Create a user agent object my $ua = new LWP::UserAgent; $ua->agent("CueCat/0.1 " . $ua->agent); # Create a request my $req = new HTTP::Request GET => $url; $req->content_type('application/x-www-form-urlencoded'); # Pass request to the user agent and get a response back my $res = $ua->request($req); my $content = $res->content; my @content = split("\n", $content); my $start = 0; foreach (@content) { if(/<!-- Main Text Table -->/) { $start++; } if($start > 0) { s/\ / /g; my $foo = HTML::FormatText->new->format(parse_html($_)); if($foo !~ /^\s+$/) { if($foo !~ /IMAGE/) { if($foo !~ /TABLE NOT SHOWN/) { push(@book, $foo); } } } if(/Pub\. Date/) { $start = 0; } } } my ( @Title, @Author, @Publisher, @Isbn, @PubData, @ListPrice ); my ( $Title, $Author, $Publisher, $Isbn, $PubData, $ListPrice ); my @Lines; my @eachBook; my $var; my $counter = 0; my $i = 0; foreach $book ( @book ) { if ($book =~ m/This title has a full description. Click the Title +to view the details./ ) { next; } if ($book =~ m/Add this item to your basket. You can buy the conte +nts of your basket at any time by pressing 'Checkout' above./ ) { next; } push ( @Lines, $book ); } foreach $var ( @Lines ) { @eachBook->[$i][$counter] = $var; $counter++; if ( $var =~ m/--------------------------------------------------- +------------------/ ) { $i++; $counter = 0; } } print "Content-type: text/html\n\n"; my $k = 0; for ( $i = 0; $i < @eachBook; $i++ ) { for ( $k = 0; $k < @eachBook; $k++ ) { print "@eachBook->[$i][$k]\n"; } } print "The end\n";

Edited 2002-01-12 by Ovid


In reply to Retrieving information from website using GET by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.