Here is a somewhat trimmed down version:
Output:use warnings; use LWP 5.64; use URI; use HTML::LinkExtor; my $base = "http://search.ebay.com/ws/search/SaleSearch"; my $browser = LWP::UserAgent->new; my $url = URI->new($base); $url->query_form( 'satitle'=> 'learning perl', 'sacat'=> 267, ); my %data = (); # set up the link handler sub my $link_extor = HTML::LinkExtor->new(\&handle_links); #get search results my $response = $browser->get($url); #get the links $link_extor->parse($response->content); exit; ###################################### sub handle_links { my ($tag, %links)=@_; if ($tag eq 'a') { foreach my $key (keys %links) { #search for links with Viewitem if ($key eq 'href') { if ( $links{$key} =~ m/ViewItem/) { #get the item number from the link $links{$key} =~ m/item=(\d+)/; printf "links{%s} = %s\n",$key,defined $links{$key +} ? $links{$key} : 'undef'; if (!defined $1) { die "\$1 is undefined."; } $data{$1}=$links{$key}; } } } } }
The warning is being printed because while $links{$key} =~ m/ViewItem/ matches, $links{$key} =~ m/item=(\d+)/ does not.links{href} = http://cgi.ebay.com/Learning-Perl-by-Randal-L-Schwartz-1 +997_W0QQitemZ220021417901QQihZ012QQcategoryZ2228QQssPageNameZWDVWQQrd +Z1QQcmdZViewItem $1 is undefined. at test.pl line 43.
To avoid warnings like this you should always check that the regex was succesful before checking $1.
In reply to Re: Scraping Ebay
by imp
in thread Scraping Ebay
by lv211
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |