=================================================================== RCS file: /cvs/openbsd/errata_scraper/errata_scraper.pl,v retrieving revision 1.1 retrieving revision 1.3 diff -u -r1.1 -r1.3 --- openbsd/errata_scraper/errata_scraper.pl 2011/03/21 17:26:58 1.1 +++ openbsd/errata_scraper/errata_scraper.pl 2011/03/23 19:46:16 1.3 @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $AFresh1$ +# $AFresh1: errata_scraper.pl,v 1.2 2011/03/21 16:28:15 andrew Exp $ ######################################################################## # Copyright (c) 2011 Andrew Fresh # @@ -18,38 +18,31 @@ use strict; use warnings; -use Mojo::Client; -my $client = Mojo::Client->new; - -$client->get( - 'http://www.openbsd.org/errata48.html' => sub { - shift->res->dom('li')->each( - sub { - my $e = shift; - - my $patch = $e->at('a[href$=".patch"]')->attrs->{href}; - - my $title = $e->at('strong')->replace('')->all_text; - $title =~ s/\s+/ /gxms; - - my $arch = $e->at('i')->replace('')->all_text; - $arch =~ s/\s+/ /gxms; - - # the li ends at p, but the parser expects a /li - $e->at('p')->replace(''); - - my $descr = $e->all_text; - $descr =~ s/\s+/ /gxms; - $descr =~ s/^\s+|\s+$//gxms; - - print 'Title: ', $title, "\n"; - print 'Arch: ', $arch, "\n"; - print 'Patch: ', $patch, "\n"; - print 'Descr: ', $descr, "\n"; - print "\n"; - } - ); +use Mojo::UserAgent; +use Mojo::ByteStream 'b'; + +my $base_uri = 'http://www.openbsd.org/'; + +my $ua = Mojo::UserAgent->new; + +my $ls = $ua->get( $base_uri . 'errata.html' )->res->dom('a[href^="errata"]'); + +foreach my $l ( @{$ls}[ -2, -1 ] ) { + print 'Errata for OpenBSD ', $l->text, "\n"; + foreach my $e ( + reverse @{ $ua->get( $base_uri . $l->attrs->{'href'} )->res->dom('li') + } ) + { + my $patch = $e->at('a[href$=".patch"]')->attrs->{href}; + my $title = b( $e->at('strong')->replace('')->all_text )->trim; + my $arch = b( $e->at('i')->replace('')->all_text )->trim; + my $descr = b( $e->all_text )->trim; + $descr =~ s/\s+/ /gs; + + print 'Title: ', $title, "\n"; + print 'Arch: ', $arch, "\n"; + print 'Patch: ', $patch, "\n"; + print 'Descr: ', $descr, "\n"; + print "\n"; } -); - -$client->start; +}