#!usr/local/bin/perl use CGI qw/:standard/; use HTML::Parse; use HTML::FormatText; use strict; #turn on more error checking use LWP::Simple; 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); } #GLOBAL VARIABLES my ( @book, @pairs ); #array storing all books #variables storing information on a single book my ( $book, $price, $format, $publisher, $pub_date, $req, $isbn, $buffer, $titleValue, $name, $value, $title ); #END OF GLOBAL VARIABLES #$title = param( 'title' ); my $title = 'Java'; # remove after testing my $url = "http://www.bookplace.co.uk/bookplace/results.asp?SEARCH_FIELD=KEYWORD". "&TAG=BHSLFX8X99X97X163DLT9W&CID=&SEARCH_TEXT=$title&FORM_OB=%24RANK&x=23&y=14"; my @content = split("\n", get( $url )); my $start = 0; foreach (@content) { if(//) { $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 @Lines; foreach $book ( @book ) { if ( ( $book =~ m/This title has a full description. Click the Title to view the details./ )|| ( $book =~ m/Add this item to your basket. You can buy the contents of your basket at any time by pressing 'Checkout' above./ ) ) { next; } push ( @Lines, $book ); } my $counter = 0; my $i = 0; my @eachBook; foreach my $var ( @Lines ) { @eachBook->[$i][$counter] = $var; $counter++; if ( $var =~ m/---------------------------------------------------------------------/ ) { $i++; $counter = 0; } } print header, start_html( -title -> 'WTF' ); for my $i ( 0 .. $#eachBook) { for my $k ( 0 .. $#eachBook ) { print p( @eachBook->[$i][$k] ); } } print end_html;