Reputation: 271
How to obtain Wikidata ID from English Wikipedia article name, also for redirects? Is there API call?
Example:
Karachi >> Q8660
Karaachi >> Q8660
How to approach changes in assignment? Now Media in Karachi is redirect to Media of Pakistan (Wikidata item Q6805922), but can be own article later.
Upvotes: 26
Views: 11152
Reputation: 598
As well as the accepted answer you can also use the Wikidata API directly passing in a site and a title.
The docs are at https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities
Get the entity for http://en.wikipedia.org/wiki/Karachi:
Upvotes: 4
Reputation: 2601
I needed to do it in Google Sheets, and was able to do it with a formula like this. It assumes the Wikipedia title is in column B. Copy down to the rows you need
=IMPORTXML(concat("https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&ppprop=wikibase_item&redirects=1&format=xml&titles=",B1),"//@wikibase_item")
Another suggestion is to use the dump https://dumps.wikimedia.org/enwiki/latest/enwiki-latest-page_props.sql.gz, 230Mb zipped
Upvotes: 3
Reputation: 7036
Use Wikipedia API to create a query with property pageprops and resolving redirects:
https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&ppprop=wikibase_item&redirects=1&titles=ARTICLE_NAME
In your case, for Wikipedia articles "Media in Karachi" and "Media of Pakistan" you will get the same Wikidata item ID: Q6805922. Same thing for "Karaachi" and "Karachi" → Q8660.
Upvotes: 32