Accessing main picture of wikipedia page by API

前端 未结 14 1870
没有蜡笔的小新
没有蜡笔的小新 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

    Check out the MediaWiki API example for getting the main picture of a wikipedia page: https://www.mediawiki.org/wiki/API:Page_info_in_search_results.

    As other's have mentioned, you would use prop=pageimages in your API query.

    If you also want the image description, you would use prop=pageimages|pageterms instead in your API query.

    You can get the original image using piprop=original. Or you can get a thumbnail image with a specified width/height. For a thumbnail with width/height=600, piprop=thumbnail&pithumbsize=600. If you omit either, the image returned in the API callback will default to a thumbnail with width/height of 50px.

    If you are requesting results in JSON format, you should always use formatversion=2 in your API query (i.e., format=json&formatversion=2) because it makes retrieving the image from the query easier.

    Original Size Image:

    https://en.wikipedia.org/w/api.php?action=query&format=json&formatversion=2&prop=pageimages|pageterms&piprop=original&titles=Albert Einstein
    

    Thumbnail Size (600px width/height) Image:

    https://en.wikipedia.org/w/api.php?action=query&format=json&formatversion=2&prop=pageimages|pageterms&piprop=thumbnail&pithumbsize=600&titles=Albert Einstein
    
    0 讨论(0)
  • 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
    0 讨论(0)
提交回复
热议问题