0

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.

1

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()
  • It's the same answer that I provided, but you added the silent option -s and piped the result to a json processor. Anyway, I will accept yours, because the output is way nicer at the command line. – Dominic108 Nov 6 at 18:04
0

Simply add the -L option and, usually, you don't need the -X GET option, because it's the default:

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

or simply use wget:

wget "https://en.wikipedia.org/api/rest_v1/page/random/summary" -O outputfile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.