1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
6 package quotesite::AmazonGrabber;
8 use quotesite::GrabberBase;
9 @ISA = qw(quotesite::GrabberBase);
11 use LWP::Simple qw(!get);
20 my $self = $class->SUPER::new();
22 $self->{'NAME'} = 'amazon';
23 $self->{'PATTERNS'} = ['(https?://(?:[-a-zA-Z0-9_.]+\.)*amazon\.(?:com|de|co\.uk|fr)/.*[dg]p(?:/product)?/([[:alnum:]]{10}))'];
26 $self->_prepare_parameters();
44 $metadata->{'URL'} = $url;
45 $metadata->{'ID'} = $2;
46 $metadata->{'TYPE'} = 'quote';
47 $metadata->{'SOURCE'} = $self->{'NAME'};
48 $metadata->{'CONTENT'} = undef;
50 # Get the HTML file containing the quote
51 unless(defined($content = LWP::Simple::get($url))) {
52 $self->error('Could not download quote');
56 $self->debug($content);
58 $p = HTML::TokeParser->new(\$content);
60 OUTER: while ($t = $p->get_tag('h1')) {
61 if (exists($t->[1]->{'class'}) && ($t->[1]->{'class'} eq 'parseasinTitle')) {
62 $metadata->{'CONTENT'} = encode('utf8', decode('iso8859-1', $p->get_text('/h1')));
63 $metadata->{'CONTENT'} =~ s/^\s*//;
64 $metadata->{'CONTENT'} =~ s/\s*$//;
69 unless(defined($metadata->{'CONTENT'})) {
70 $self->error('Could not extract quote content');