in reply to Retrieving information from website using GET
I'm very confused. You are already using a GET request. This script has a combination of some very experienced code (detailed use of modules) and some very hacked in code (incorrectly parsing form data, print a 'text/html' header and then printing plain text, poor scoping on variables, poor regular expressions, etc.). I did a quick (and incomplete) cleanup on the code, but I don't really think I'm going to comment on it. Something here is a bit odd. Are you maintaining someone else's code? What gives?
#!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_FIE +LD=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(/<!-- 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 @Lines; foreach $book ( @book ) { if ( ( $book =~ m/This title has a full description. Click the Tit +le to view the details./ )|| ( $book =~ m/Add this item to your basket. You can buy the co +ntents 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;
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|