问题
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 IDsitefilter=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