jdavis <[EMAIL PROTECTED]> wrote:
: 
: Hello,
: I have a script that gets items and corresponding price from
: a web site. all goes well until i put the item and price in
: a hash. When i try to print key and value from the hash it
: comes out all weired. Could some one take a look and see
: what im doing wrong.

    You're defining an error as "comes out all weird".
    You're not using strict.
    You're escaping characters unnecessarily.
    You're using regexes to parse html.


: p.s. sorry about the wrap...its my mail client :(

    You could change your tabs to spaces and wrap the long
lines yourself for more clarity.


    As Wiggins warned, you do have permission to scrape
this page, right? I placed the page content in a file for
testing. Read the HTML::TokeParser POD for instructions
to parse a scalar.


use strict;
use warnings;
use Data::Dumper;
use HTML::TokeParser;

my $page = HTML::TokeParser->new("foo3.html") ||
                             die "Can't open: $!";

my %items;
while ( my $token = $page->get_token ) {

    next unless
        $token->[0] = 'C'
    &&  $token->[1] =~
           /### Display Item's Name and make a hyperlink ###/;

    $page->get_tag( 'b' );
    my $item_name = $page->get_trimmed_text( '/b' );

    $items{ $item_name } = fetch_price( $page );
}

sub fetch_price {
    my $page = shift;
    while ( my $token = $page->get_tag( 'font' ) ) {
        return
            $page->get_trimmed_text( '/font' )
                if
                    defined $token->[1]{color}
                &&  $token->[1]{color} eq 'red';
    }
}

print Dumper \%items;

__END__

HTH,

Charles K. Clarkson
-- 
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to