Utilisateur:KelBot/kbwlh

Un article de Wikipédia, l'encyclopédie libre.

#!/usr/bin/perl
 
use KelBot;
use strict;
use Getopt::Long;
 
my $pw;
 
my $page;
 
GetOptions('page=s' => \$page);
 
if ($page) {
    kbls($page);
} else {
    unless ($page) {
        while ($page = <STDIN>) {
            $page =~ s/\n//;
            kbls($page);
        }
    }
}
 
sub kbls {
    my $page = shift;
    return unless ($page);
 
    unless ($pw) {
        $pw = KelBot->new('kbwlh');
        $pw->login();
    }
 
    $page = `php -q ./urlencode.php "$page"`;
    $page =~ s/ \n//;
 
    foreach my $link ($pw->what_links_here($page)) {
        my $title =  $link->{title};
 
        next unless ($pw->encyclo($title));
 
        $title =~ s/ /_/g;
        print $title."\n";
    }
}