How to get Wikipedia content using Wikipedia's API?

bbnn picture bbnn · Aug 25, 2011 · Viewed 108.6k times · Source

I want to get the first paragraph of a Wikipedia article.

What is the API query to do so?

Answer

Gabe picture Gabe · Aug 25, 2011

See this section on the MediaWiki docs

These are the key parameters.

prop=revisions&rvprop=content&rvsection=0

rvsection = 0 specifies to only return the lead section.

See this example.

http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&rvsection=0&titles=pizza

To get the HTML, you can use similarly use action=parse http://en.wikipedia.org/w/api.php?action=parse&section=0&prop=text&page=pizza

Note, that you'll have to strip out any templates or infoboxes.