Wikipedia API - get random page(s)

You're close. generator=random is the right way to go. You can then use various prop values to get the info you want:

  • Page title is always included.

  • To get the text, use prop=revisons along with rvprop=content.

  • To get all images used on the page, use prop=images.

    Note that this will often include images you're probably not interested in, like icons and flags. To fix that, you might try instead prop=pageimages, though it doesn't seem to work always. Or you could try using both.

So, the final query could look like this:

https://en.wikipedia.org/w/api.php?format=json&action=query&generator=random&grnnamespace=0&prop=revisions|images&rvprop=content&grnlimit=10


If you'd rather use their REST api,

curl -X GET "https://en.wikipedia.org/api/rest_v1/page/random/summary"

Documentation