wikipedia2text – A Command Line tool for querying the Wikipedia articles

Hi folks I am back with another interesting topic called wikipedia2text. It’s a small Shell script to query the Wikipedia articles in console, also it can open the article in any browser.

This shell script uses text-browser to query and render Wikipedia articles. The output will be printed to standard out. It Currently supports around 30 Wikipedia languages.

Most of us prefer Wikipedia to know the detailed information about any company or any product information & it’s history. For any google search by default Wikipedia link comes in Top 5.

Wikipedia has 40 millions articles in more than 299 different languages and the English Wikipedia is the largest one. Are you NIX guys and looking for CLI utility to read Wikipedia page from command line then you are in the right page. Give a try and let me know your feedback.

Some people may ask why? We want separate tool for that when we have a text mode browser since it’s rendering articles through text-browsers because it doesn’t offer the same features alike wikipedia2text utility.

This script uses text-browser to query and render Wikipedia articles so, install any one of below text mode browser then proceed wikipedia2text installation.

Suggested Read : Best Text based (Command Line) Web Browsers for Linux

How to install wikipedia2text in Linux

Debian based distributions are included this package in default repository, however it’s not a big deal to install in other distributions too. Actually we are not going to install, just clone the repository and move the wikipedia2text file alone to /bin directory in the same name or if you want to make short and sweet then rename as wiki-cli because i did the same.

$ git clone https://github.com/chrisbra/wikipedia2text 
$ sudo mv wikipedia2text/wikipedia2text /bin/wiki-cli
$ rm -Rf wikipedia2text

When you Launch the script without any arguments, by default it display help page.

$ wiki-cli

NAME

    This script uses text-browser to query and render Wikipedia
    articles. The output will be printed to standard out.

SYNOPSIS
    wiki-cli [-BCnNoOpPsSuU] [-b prog] [-c patt] [-i patt] [-l lang] [-X browseroptions] query
    wiki-cli -o [-b prog] [-l lang] query
    wiki-cli [-h]
    wiki-cli -v|-r

    -n  do not colorize       -N simple colorization (alias -C)
    -p  display using a pager      -P  don't use pager
    -o  open Wikipedia article in browser   -O  don't open in browser
    -s  display only a summary      -S display whole article
    -u  Just output the query URL     -U open URL in browser
    -v  display version       -h display help

    -r                    open Random Page
    -i patt               colorize pattern (case insensitive)
    -I patt               colorize pattern (case-sensitive, alias -c)
    -b prog               use prog as browser (by default to invoke elinks, links2,
                          links, lynx or w3m, if found)
    -l lang               use language (currently supported are: af, als, ca, cs, da,
                          de, en, eo, es, fi, fr, hu, ia, is, it, la, lb, nds, nl, nn,
                          no, pl, pt, rm, ro, simple, sk, sl, sv, tr)
    -W url                use url as base-URL for wikipedia (e.g. use a different
                          Wiki, Querying this URL will happen by appending the search
                          term.
    -X "browseroptions"   pass through options to browser, e.g., "-width 180"
                          (warnings: must be in quotes; browser specific, not checked)

    Query can be any term to search for at Wikipedia. Special
    characters will be taken care of. Note that only one query term is
    supported, however this term can consist of one or more words.

    Configuration can also be controlled by creating a runcontrol file
    .wiki-clirc your home directory.

    Note that when requesting to open the article in a browser, other
    parameters will be ignored. The same holds for the options -h and
    -v.

To read any specific article from Wikipedia, run the following command and press space bar to move next page.

$ wiki-cli -p fedora

To read article in other languages from Wikipedia, run the following command. We have tested French language. Current it supports 30 languages.

$ wiki-cli -pl fr arch linux

Supported languages are.

    -l lang               use language (currently supported are: af, als, ca, cs, da,
                          de, en, eo, es, fi, fr, hu, ia, is, it, la, lb, nds, nl, nn,
                          no, pl, pt, rm, ro, simple, sk, sl, sv, tr)

To open Wikipedia article in browser, run the following command.

$ wiki-cli -po opensuse

If you want to know the query URL, run the following command.

$ wiki-cli -u debian
http://en.wikipedia.org/wiki/debian
/usr/bin/elinks  -dump http://en.wikipedia.org/wiki/debian

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

Your email address will not be published. Required fields are marked *