Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Retrieving information from website using GET
by Chady (Priest) on Jan 12, 2002 at 20:25 UTC

    first of all, I don't think that you did write this script, because if you did, you'd know that this is a silly thing to ask, and your program already GETs the page.

    second this is a very poor programmed script: you use CGI and then go on and parse the parameters manually (not mentioning that it is also done wrong).... and since you're importing LWPs try LWP::Simple with this snippet at the top:

    use CGI qw/:standard/; use LWP::Simple; my $title = param('title'); 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 = get($url);

    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/
(Ovid) Re: Retrieving information from website using GET
by Ovid (Cardinal) on Jan 12, 2002 at 20:39 UTC

    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.

Re: Retrieving information from website using GET
by n3dst4 (Scribe) on Jan 12, 2002 at 22:47 UTC
    This reminds me of another recent node. They're either by the same nonny mouse or two nonny mice with coincidentally similar requirements - either way my reply is on the other one :¬)