Search code examples
mediawiki-api

How to use MediaWiki's api to get the first section of an article?


I want to find the first section of a randomly-chosen page and have it rendered in HTML.

Here is what I have tried: http://en.wikipedia.org/w/api.php?format=xml&action=query&generator=random&prop=revisions&rvprop=content&rvparse

But it keeps on returning a result in user talks and others that I'm not interested in.(i.e they are in other namespaces)

I don't know how to specify namespaces here. Parameters like rnnnamespace and rvnamespace don't work.

I'd prefer that this is a single API call, but if not possible how can I do it in two?


Solution

  • I played with the API sandbox and this seems to do what I want:

    api.php?format=xml&action=query&generator=random&prop=revisions&rvprop=content&rvparse=&rvsection=0&grnnamespace=0