Get Extract From Wikipedia Page With The Wikipedia API

July 3, 2020 by Andreas Wik

Wikipedia API

I recently needed a way to fetch the beginning of Wikipedia pages (leadermap.org). The Wikipedia API gives you a quick way to do this without authenticating.

The API endpoint lives at: https://en.wikipedia.org/w/api.php

We can get the extract from a page in JSON format by passing a few parameters to it, namely format=json, origin=*action=query, prop=extractsexplaintextexintrotitles=my+title

So to get the extract of Kobe Bryant’s Wikipedia page, I would use:

https://en.wikipedia.org/w/api.php?format=json&origin=*&action=query&prop=extracts&explaintext=false&exintro&titles=Kobe+Bryant

Play around with the parameters for different results. If you leave explaintext out, for example, the extract will come back with HTML tags. 

GLHF

Share this article

Recommended articles

@awikio