a3nm's blog

List Wikipedia categories on stdout

— updated

This is not rocket science, but maybe it can be useful to someone, or it can serve as a simple example of how you can query the Mediawiki API (or any JSON API) using Python 3. The two arguments are the name of the wiki (like "en.wikipedia.org") and the name of the category, and the output is the contents of the category, one item per line. Request continuations are handled, the script will pause for two seconds every request (ie. every 500 items).

For the code (public domain), see here: wikicateg

Here's an example:

$ lswikicateg.py en.wikipedia.org Experiments
Animal testing
Carryover effect
Checking whether a coin is fair
Control variable
Cranfield Experiments
Generality (psychology)
Inflatable Antenna Experiment
Jerry Klein's 2006 radio experiment
LOCAD
Long-term experiment
Lost in the mall technique
Natural experiment
Scientific control
The Third Wave
Category:Experimental archaeology
Category:Experimental economics
Category:Experimental film
Category:Experimental mathematics
Category:Experimental mechanics
Category:Experimental medical treatments
Category:Experimental methods of birth control
Category:Experimental missiles
Category:Experimental music
Category:Experimental physics
Category:Experimental psychology
Category:Experimental rockets
Category:Science experiments
Category:Experimental television stations
Category:Thought experiments
Category:Experimental vehicles
comments welcome at a3nm<REMOVETHIS>@a3nm.net