WWW::Wikipedia - Automated interface to the Wikipedia
use WWW::Wikipedia; my $wiki = WWW::Wikipedia->new(); ## search for 'perl' my $result = $wiki->search( 'perl' ); ## if the entry has some text print it out if ( $result->text() ) { print $result->text(); } ## list any related items we can look up print join( "\n", $result->related() );
WWW::Wikipedia provides an automated interface to the Wikipedia http://www.wikipedia.org, which is a free, collaborative, online encyclopedia. This module allows you to search for a topic and return the resulting entry. It also gives you access to related topics which are also available via the Wikipedia for that entry.
The constructor. You can pass it a two letter language code, or nothing to let it default to 'en'.
## Default: English my $wiki = WWW::Wikipedia->new(); ## use the French wiki instead my $wiki = WWW::Wikipedia->new( language => 'fr' );
WWW::Wikipedia is a subclass of LWP::UserAgent. If you would like to have more control over the user agent (control timeouts, proxies ...) you have full access.
## set HTTP request timeout my $wiki = WWW::Wikipedia->new(); $wiki->timeout( 2 );
This allows you to get and set the language you want to use. Two letter language codes should be used. The default is 'en'.
my $wiki = WWW::Wikipedia->new( language => 'es' ); # Later on... $wiki->language( 'fr' );
Which performs the search and returns a WWW::Wikipedia::Entry object which you can query further. See WWW::Wikipedia::Entry docs for more info.
$entry = $wiki->search( 'Perl' ); print $entry->text();
If there's a problem connecting to Wikipedia, undef will be returned and the error message will be stored in error().
undef
error()
This is a generic error accessor/mutator. You can retrieve any searching error messages here.
Clean up results. Strip HTML.
Watch the development of Special:Export XML formatting, eg: http://en.wikipedia.org/wiki/Special:Export/perl
LWP::UserAgent
Ed Summers, <ehs@pobox.com>
Brian Cassidy, <bricas@cpan.org>
Copyright 2005 by Ed Summers
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install WWW::Wikipedia, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Wikipedia
CPAN shell
perl -MCPAN -e shell install WWW::Wikipedia
For more information on module installation, please visit the detailed CPAN module installation guide.