1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
6 package quotesite::QdbGrabber;
8 use quotesite::GrabberBase;
9 @ISA = qw(quotesite::GrabberBase);
11 use LWP::Simple qw(!get);
20 my $self = $class->SUPER::new();
22 $self->{'NAME'} = 'qdb.us';
23 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*qdb\.us/(\d+))'];
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(sprintf('http://qdb.us/?%s', $2)))) {
52 $self->error('Could not download quote');
56 $p = HTML::TokeParser->new(\$content);
58 OUTER: while ($t = $p->get_tag('span')) {
59 if (exists($t->[1]->{'class'}) && ($t->[1]->{'class'} eq 'qt')) {
60 $metadata->{'CONTENT'} = encode('utf8', decode('iso8859-1', $p->get_text('/span')));
65 unless(defined($metadata->{'CONTENT'})) {
66 $self->error('Could not extract quote content');