[BACK]Return to errata_scraper.pl CVS log [TXT][DIR] Up to [local] / openbsd / errata_scraper

File: [local] / openbsd / errata_scraper / errata_scraper.pl (download)

Revision 1.2, Mon Mar 21 16:28:15 2011 UTC (13 years, 2 months ago) by andrew
Branch: MAIN
Changes since 1.1: +20 -34 lines

better, shorter version with newer Mojo::UserAgent

#!/usr/bin/perl
# $AFresh1: errata_scraper.pl,v 1.2 2011/03/21 16:28:15 andrew Exp $
########################################################################
# Copyright (c) 2011 Andrew Fresh <andrew@afresh1.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
########################################################################
use strict;
use warnings;

use Mojo::UserAgent;
use Mojo::ByteStream 'b';

Mojo::UserAgent->new->get('http://www.openbsd.org/errata48.html')
  ->res->dom('li')->each(
    sub {
        my $e = shift;

        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";
    }
);