当页面标题与文件名不同时,如何查询维基百科api的文件?

时间:2013-11-12 20:52:35

标签: api mediawiki wikipedia wikipedia-api mediawiki-api

我正试图从维基百科中检索阿富汗的徽章图像。

到目前为止我所做的是:

检索阿富汗的信息框through here

并解析结果以提取:

  

“image_coat = Afghanistan.svg的徽章”

通常,我会继续querying the image info here,但此链接缺少真实的图片网址。

问题是,对于阿富汗来说,图片实际上是"Emblem_of_Afghanistan.svg"而不是"Coat_of_arms_of_Afghanistan.svg".

但是,this page正确显示文件"Emblem_of_Afghanistan.svg".


所以我有点被困在这里。如果它只是阿富汗,我可以手动纠正它,但这个问题出现在许多文件中。

1 个答案:

答案 0 :(得分:4)

真实文件为File:Emblem_of_Afghanistan.svg的原因是因为Commons页面File:Coat of arms of Afghanistan.svg是重定向到File:Emblem of Afghanistan.svg。不幸的是,prop=imageinfo API doesn't currently handle Commons redirects

要解决这个问题,当发生这种情况时(您可以在响应中通过imagerepository识别,但没有URL *),您可以改为查询Commons API,同时还指定redirects:{ {3}}

*您链接的查询不正确,它缺少File:前缀。正确的查询是:http://commons.wikimedia.org/w/api.php?action=query&titles=File:Coat_of_arms_of_Afghanistan.svg&prop=imageinfo&iiprop=url&format=json&redirects

相关问题