1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
4 # Grabber for german-bash.org
6 package quotesite::GermanBashGrabber;
8 use quotesite::GrabberBase;
9 @ISA = qw(quotesite::GrabberBase);
19 my $self = $class->SUPER::new();
21 $self->{'NAME'} = 'germanbash';
22 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*german-bash\.org/(\d+))',
23 '(http://(?:[-a-zA-Z0-9_.]+\.)*german-bash\.org/action/show/id/(\d+))'];
26 $self->_prepare_parameters();
39 my $ua = LWP::UserAgent->new('agent' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)');
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 $content = $ua->get(sprintf('http://german-bash.org/%s', $2));
52 unless($content->is_success) {
53 $self->error('Could not download quote');
56 $content = $content->decoded_content();
58 $p = HTML::TokeParser->new(\$content);
60 while ($t = $p->get_tag('div')) {
61 if (exists($t->[1]->{'class'}) && ($t->[1]->{'class'} eq 'zitat')) {
62 $metadata->{'CONTENT'} = $p->get_text('/div');
63 $metadata->{'CONTENT'} =~ s/^\s*//mg;
68 unless(defined($metadata->{'CONTENT'})) {
69 $self->error('Could not extract quote content');