Closed youssefavx closed 4 years ago
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'
e.g. something like this: