1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
6 package BashOrgGrabber;
9 @ISA = qw(GrabberBase);
11 use LWP::Simple qw(!get);
19 my $self = $class->SUPER::new();
21 $self->{'NAME'} = 'bash.org';
22 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*bash\.org/\?(\d+))'];
25 $self->_prepare_parameters();
42 $metadata->{'URL'} = $url;
43 $metadata->{'ID'} = $2;
44 $metadata->{'TYPE'} = 'quote';
45 $metadata->{'SOURCE'} = $self->{'NAME'};
46 $metadata->{'CONTENT'} = undef;
48 # Get the HTML file containing the quote
49 unless(defined($content = LWP::Simple::get(sprintf('http://bash.org/?%s', $2)))) {
50 $self->error('Could not download quote');
54 $p = HTML::TokeParser->new(\$content);
56 while ($t = $p->get_tag('p')) {
57 if (exists($t->[1]->{'class'}) && ($t->[1]->{'class'} eq 'qt')) {
58 $metadata->{'CONTENT'} = $p->get_text('/p');
62 unless(defined($metadata->{'CONTENT'})) {
63 $self->error('Could not extract quote content');