Is it possible to get the wikidata ID from a Wikipedia article name? #49
Answered
by
dahlia
youssefavx
asked this question in
Q&A
-
e.g. something like this:
|
Beta Was this translation helpful? Give feedback.
Answered by
dahlia
Jul 27, 2020
Replies: 1 comment
-
This project does not directly cover Wikipedia, but you can use Wikipedia API to find a Wikidata ID: https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&titles=Physics >>> import json
>>> from urllib.parse import quote
>>> from urllib.request import urlopen
>>> title = 'Physics'
>>> url = f'https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&format=json&titles={quote(title)}'
>>> r = urlopen(url)
>>> pages = json.load(r)
>>> r.close()
>>> page, = pages['query']['pages'].values()
>>> wikibase_item = page['pageprops']['wikibase_item']
>>> wikibase_item
'Q413' |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dahlia
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This project does not directly cover Wikipedia, but you can use Wikipedia API to find a Wikidata ID:
https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&titles=Physics