Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing main picture of wikipedia page by API

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?

like image 390
insomiac Avatar asked Dec 02 '11 22:12

insomiac


People also ask

How do I get an image from Wikipedia API?

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.

How do you find the source of an image on Wikipedia?

If you click on any image on Wikipedia, you will go to a page about the image itself. This image page will have information on the image's source, authorship, and copyright licensing, along with a more detailed description of the image.

Is there an API for Wikipedia?

What is the Wikipedia API? The Wikipedia API (official documentation) is supported by the MediaWiki's API and provide access to Wikipedia and other MediaWiki data without interacting with the user interface.

Where are Wikipedia images stored?

All images used must be legal in the United States, where Wikimedia's servers are located. Images are stored on the Wikipedia website or the partner Wikimedia Commons website.


2 Answers

You can get the thumbnail of any wikipedia page using prop=pageimages. For example:

http://en.wikipedia.org/w/api.php?action=query&titles=Al-Farabi&prop=pageimages&format=json&pithumbsize=100 

And you will get the thumbnail full URL.

like image 129
Assaf Shemesh Avatar answered Sep 28 '22 17:09

Assaf Shemesh


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.

like image 27
varatis Avatar answered Sep 28 '22 16:09

varatis