Accessing main picture of wikipedia page by API

前端 未结 14 1954
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 18:15

Is there any way I can access the thumbnail picture of any wikipedia page by using an API? I mean the image on the top right side in box. Is there any APIs for that?

14条回答
  •  情深已故
    2020-11-30 18:47

    Like Anuraj mentioned, the pageimages parameter is it. Look at the following url that'll bring about some nifty stuff:

    https://en.wikipedia.org/w/api.php?action=query&prop=info|extracts|pageimages|images&inprop=url&exsentences=1&titles=india
    

    Her are some interesting parameters:

    • The two parameters extracts and exsentences gives you a short description you can use. (exsentences is the number of sentences you want to include in the excerpt)
    • The info and the inprop=url parameters gives you the url of the page
    • The prop property has multiple parameters separated by a bar symbol
    • And if you insert the format=json in there, it is even better

提交回复
热议问题