WWW::Wikipedia(3pm)

πŸ“¦
version 2.05 Β· 2 versions
  • 2.05 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 2.05 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– WWW::Wikipedia πŸ’–

okay bestie, so this is the perl manual page for WWW::Wikipedia β€” it's filed under User Contributed Perl Documentation and it lives in section 3pm of your man pages. it's giving "i want to talk to wikipedia from my perl script and i want it to be easy." and it IS easy. slay. ✨


🌸 NAME 🌸

WWW::Wikipedia β€” an automated interface to the Wikipedia. periodt. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

here's the vibe, literally copy-paste coded:

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() );

look at her go 🫢


πŸŽ€ DESCRIPTION πŸŽ€

WWW::Wikipedia hands you an automated interface to the Wikipedia <http://www.wikipedia.org> β€” which is, no cap, a free, collaborative, online encyclopedia. 🌈

with this module you can search for a topic and get the resulting entry back. it also gives you access to the related topics that are also available via the Wikipedia for that entry. it's giving main character research assistant energy fr fr. πŸ”₯


✨ INSTALLATION ✨

to install this module, type the following β€” yes, in this order, don't skip steps bestie:

perl Makefile.PL
make
make test
make install

make test is not optional. we test. we love her. πŸ’œ


πŸ‘‘ METHODS πŸ‘‘

🧚 new()

the constructor. you can pass it a two letter language code, or nothing at all 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. so if you want more control over the user agent (timeouts, proxies, all that...), you have full access. iconic inheritance moment honestly.

## set HTTP request timeout
my $wiki = WWW::Wikipedia->new();
$wiki->timeout( 2 );

you can turn off the following of wikipedia redirect directives by passing a false value to "follow_redirects".

together with the Wiki markup, some entries include HTML tags. they can be stripped out using the "clean_html" option:

my $wiki = WWW::Wikipedia->new( clean_html => 1 );

see the "clean_html" documentation below for details. ⬇️

πŸ“ language()

this lets you 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' );

switch languages whenever, she's flexible like that πŸ’…

🌸 clean_html()

lets you get/set whether HTML is being stripped out.

# set HTML strip
$wiki->clean_html( 1 );

this option removes all tags and the attributes they might have. their contents, however, is maintained (for now). comments are also removed. lowkey important to know that, so read the TODO below too bestie. πŸ‘€

πŸ¦‹ follow_redirects()

by default, wikipeda redirect directives are followed. set this to false to turn that off.

(yes the original says "wikipeda" β€” we keep the lore, no editing the sacred texts πŸ’€)

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(). so like, check for undef bestie, don't just go printing stuff and getting mad at perl. 😭

⭐ random()

this method fetches a random wikipedia page. pure chaos. we love her. 🎲

πŸ’œ error()

this is a generic error accessor/mutator. you can retrieve any searching error messages here. it's the group chat where the problems get reported.


πŸ™ˆ TODO πŸ™ˆ

things that are still cooking:

  • Be more specific on the HTML clean methodology. For now all tags are removed, keeping only their contents. In the future the behaviour might change accordingly with each specific tag.
  • Watch the development of Special:Export XML formatting, eg: <http://en.wikipedia.org/wiki/Special:Export/perl>

🌈 SEE ALSO 🌈

  • LWP::UserAgent

πŸŽ€ REPOSITORY πŸŽ€

<https://github.com/edsu/www-wikipedia>

go star it, it's the polite thing to do 🫢


πŸ’– AUTHORS πŸ’–

  • Ed Summers <ehs@pobox.com>
  • Brian Cassidy <bricas@cpan.org>

legends, both of them πŸ‘‘


Copyright 2003-2017 by Ed Summers

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page bestie!! 🌟 this one came from perl v5.34.0 and it's dated 2022-06-28 β€” so yeah, vintage-ish but still serving. now go query wikipedia responsibly, mwah πŸ’‹βœ¨πŸŒΈ

πŸ“¦ where this page comes from