Accessing main picture of wikipedia page by API

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

    http://en.wikipedia.org/w/api.php

    Look at prop=images.

    It returns an array of image filenames that are used in the parsed page. You then have the option of making another API call to find out the full image URL, e.g.: action=query&titles=Image:INSERT_EXAMPLE_FILE_NAME_HERE.jpg&prop=imageinfo&iiprop=url

    or to calculate the URL via the filename's hash.

    Unfortunately, while the array of images returned by prop=images is in the order they are found on the page, the first can not be guaranteed to be the image in the info box because sometimes a page will include an image before the infobox (most of the time icons for metadata about the page: e.g. "this article is locked").

    Searching the array of images for the first image that includes the page title is probably the best guess for the infobox image.

提交回复
热议问题