How to get Wikipedia page from Wikidata Id?

大憨熊 提交于 2020-01-14 08:00:29

问题


How to get Wikipedia page (in a particular language, say French) from the Wikidata Id (ex: Q19675)? The question seems obvious but strangely, I find nothing on the web. I'm looking for a url command that I could use with requests Python module, something like:

url = "https://www.wikidata.org/w/api.php?action=some_method&ids=Q19675"
r = requests.post(url, headers={"User-Agent" : "Magic Browser"})

Someone can help me?


回答1:


You have to use MediaWiki API with action=wbgetentities:

https://www.wikidata.org/w/api.php?action=wbgetentities&format=xml&props=sitelinks&ids=Q19675&sitefilter=frwiki

where:

  • ids=Q19675 - Wikidata item ID
  • sitefilter=frwiki - to get page title only for French Wikipedia

For your example response will be:

<api success="1">
    <entities>
        <entity type="item" id="Q19675">
            <sitelinks>
                <sitelink site="frwiki" title="Musée du Louvre">
                    <badges/>
                </sitelink>
            </sitelinks>
        </entity>
    </entities>
</api>


来源:https://stackoverflow.com/questions/37079989/how-to-get-wikipedia-page-from-wikidata-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!