Wikipedia API – Retrieve Random Pages Using REST API

mediawikiwikipedia

I try to get a random page in Wikipedia using their rest api. I do as suggested in https://stackoverflow.com/a/56518662 :

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

but nothing is returned. Perhaps, it's because there is a redirect. What should I do? The answer is perhaps obvious if we read the curl documentation.

Best Answer

Using the command line:

curl -sL "https://en.wikipedia.org/api/rest_v1/page/random/summary" | jq

Using the Python programming language:

import requests
page = requests.get("https://en.wikipedia.org/api/rest_v1/page/random/summary").json()