Pergunta

I'm trying to retrieve Afghanistan's coat of arms image from wikipedia.

What I'm doing so far is:

Retrieve the infobox for Afghanistan through here.

and parse the result to extract:

"image_coat = Coat of arms of Afghanistan.svg"

Normally, I'd continue by querying the image info here, but this link is missing the real image url.

The problem is that, for Afghanistan, the image is actually "Emblem_of_Afghanistan.svg" instead of "Coat_of_arms_of_Afghanistan.svg".

However, this page correctly displays the file "Emblem_of_Afghanistan.svg".


So I'm kind of stuck here. If it were only Afghanistan, I could manually correct it, but this issue arises for many files.

Foi útil?

Solução

The reason why the real file is File:Emblem_of_Afghanistan.svg is because the Commons page File:Coat of arms of Afghanistan.svg is a redirect to File:Emblem of Afghanistan.svg. Unfortunately, the prop=imageinfo API doesn't currently handle Commons redirects.

To work around that, when this happens (which you can recognize by imagerepository in the response, but no URL*), you can instead query the Commons API, while also specifying redirects: http://commons.wikimedia.org/w/api.php?action=query&titles=File:Coat_of_arms_of_Afghanistan.svg&prop=imageinfo&iiprop=url&format=json&redirects

* The query you linked to isn't right, it's missing the File: prefix. The right query is: http://en.wikipedia.org/w/api.php?action=query&titles=File:Coat_of_arms_of_Afghanistan.svg&prop=imageinfo&iiprop=url&format=json

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top