package WWW::ShopBot::TW::tcr;
use strict;
use LWP::UserAgent;
use LWP::Simple;
use Data::Dumper;
use WWW::ShopBot::Driver;
use HTML::LinkExtractor;

our @ISA = qw(WWW::ShopBot::Driver);
our $VERSION = '0.01';

our $firsturl = 'http://www.tcr.com.tw/search.asp';

sub query {
    my $pkg = shift;
    my ($content, $item, @result, %next, %links);
    my $ua = new LWP::UserAgent(proxy=>$pkg->{proxy}, cookie_jar=>$pkg->{jar});

    # feed the 'album search' parameters for $firsturl
    my $content = ($ua->post($firsturl, {'Search_type'=>'album',
                                         'search_term'=>$pkg->{product}
                                        }
                             ))->{_content};

    my $link_accept = qr'title_display\.asp\?cd_no=.+?'o;
    $pkg->linkextor(\$content, \%links, $link_accept);

    my $specpatt = {
	product    => qr'專輯名稱.+?<td.+?<td.+?9pt">(.+?)\&nbsp;\&nbsp;\&nbsp;<br>'s,
	productEng => qr'專輯名稱.+?<td.+?<td.+?9pt">.+?\&nbsp;\&nbsp;\&nbsp;<br>(.+?)</font>'s,
	artist     => qr'藝人/團體.+?<td.+?<td.+?9pt">(.+?)\&nbsp's,
	artistEng  => qr'藝人/團體.+?<td.+?<td.+?<td.+?<td.+?<td.+?9pt">(.+?)</font>'s, 
	price      => qr'正常價NT\$(.+?)</font>'m,
	priceRed   => qr'紅標價NT\$(.+?)</font>'s,
	photo      => qr'<img src="(/Cover/.+?)" alt'm,
	type       => qr'音樂類型.+?<font color="#0000A0" face="新細明體" style="font-size: 9pt">(.+?)\&nbsp;'s,
    };
  
    foreach my $link (keys %links){
	$item = {};
	my $content = get($link);
        if($pkg->specextor(\$content, $item, $specpatt)){
          $item->{link}  = $link;
          $item->{photo} = "http://www.tcr.com.tw".$item->{photo};	  
	  push @result, $item;
        }

    }

    \@result;
}
1;
__END__


0.01 easy <easy@cpan.org>
    - Mon, 18 Mar 2003 18:08:05 +0800


