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.


In reply to (Ovid) Re: Retrieving information from website using GET by Ovid
in thread 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.