How can I get the Infobox from a Wikipedia article by the MediaWiki API?

Erdem picture Erdem · Oct 3, 2011 · Viewed 22.5k times · Source

Wikipedia articles may have Infobox templates. By the following call I can get the first section of an article which includes an Infobox.

http://en.wikipedia.org/w/api.php?action=parse&pageid=568801&section=0&prop=wikitext

I want a query which will return only Infobox data. Is this possible?

Answer

Gaʀʀʏ picture Gaʀʀʏ · Dec 12, 2012

You can do it with a URL call to the Wikipedia API like this:

http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xmlfm&titles=Scary%20Monsters%20and%20Nice%20Sprites&rvsection=0

Replace the titles= section with your page title, and format=xmlfm to format=json if you want the article in JSON format.