1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
4 # Grabber for polit-bash.org
6 package PolitBashOrgGrabber;
9 @ISA = qw(GrabberBase);
11 use LWP::Simple qw(!get);
20 my $self = $class->SUPER::new();
22 $self->{'NAME'} = 'polit-bash.org';
23 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*polit-bash\.org/\?(\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://polit-bash.org/?%s', $2)))) {
52 $self->error('Could not download quote');
55 $content = decode("iso-8859-1", $content);
57 $p = HTML::TokeParser->new(\$content);
59 OUTER: while ($t = $p->get_tag('p')) {
60 if (exists($t->[1]->{'class'}) && ($t->[1]->{'class'} eq 'quote')) {
61 $self->debug("Found p");
62 $metadata->{'CONTENT'} = $p->get_text('/p');
67 unless(defined($metadata->{'CONTENT'})) {
68 $self->error('Could not extract quote content');
72 $metadata->{'CONTENT'} = encode("utf-8", $metadata->{'CONTENT'});