如何可靠地获取Wikipedia信息框中使用的图像? [英] How to reliably get the image used in the Wikipedia Infobox?

查看:97
本文介绍了如何可靠地获取Wikipedia信息框中使用的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何(可靠地)从API获取Wikipedia信息框中使用的主图像?

How do I (reliably) get the main image(s) used in the Wikipedia Infobox from the API?

此问题已被问过并被接受答案承认这只是一个猜测.随后的答案充其量似乎很hack,并且不会返回正确的图像.

This question has been asked before and the accepted answer admits that it is just a guess. Subsequent answers seem like a hack, at best and don't return the correct image.

例如,Jimi Hendrix Wikipedia条目使用"File:Jimi Hendrix 1967.png"作为InfoBox中的主图像.

For instance, the Jimi Hendrix Wikipedia entry uses "File:Jimi Hendrix 1967.png" as the main image in the InfoBox.

更新后的答案建议

The updated answers suggest using this url but for Jimi Hendrix (and other topics) it often returns the wrong image.

如果我

If I pull in all the images there is no way to determine which is the image used in the Infobox.

推荐答案

每个Wikipedia页面(例如 Jimi Hendrix )与Wikidata项目( Q5928 )相关联.每个Wikipedia文章的主图像(通常在Infobox模板中)由图像(P18)保存. 属性.由于所有Wikipedia模板参数很快就会移至Wikidata,因此建议您开始使用 MediaWiki Wikidata API :

Each Wikipedia page (for example Jimi Hendrix) is associated with an Wikidata item (Q5928). The main image for each Wikipedia article (usually this in the Infobox template) is kept by image (P18) property in Wikidata. Because all Wikipedia templates parameters will be moved to Wikidata very soon, I suggest you to start to use MediaWiki Wikidata API:

https://www.wikidata.org/w/api.php?action=wbgetentities&format=json&sites=enwiki&props=claims&titles=Jimi Hendrix

通过该查询,您还将获得很多其他信息,但还有主要文章图像名称:

With this query you will get a lot of other information also, but and the main article image name:

{
    ...
    "claims":{
        ...
        "P18":[{
            "mainsnak":{
                "datavalue":{
                    "value":"Jimi Hendrix 1967.png",
                },
            },
        }],
        ...
    }
}

此处我将说明如何获取图片网址也是如此.

And here I explain how to get the image URL also.

这篇关于如何可靠地获取Wikipedia信息框中使用的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆