Search code examples
wikipediawikipedia-apimediawiki-api

get wikipedia parent category of category


I am using wikimedia api and I need to get a parent category of category (e.g 'Mammals by common name' is parent category for category 'dogs'. But still I can't find out good solution. I was thinging abouth sth like

http://en.wikipedia.org/w/api.php?action=query&titles=dogs&prop=categories&clcategories=Category:Mammals%20by%20common%20name

but dogs is category not page so the output is like if 'Mammals by common name' wasnt parent category.


Solution

  • Your query checks whether the article Dogs (which is actually a redirect to Dog) belongs to Category:Mammals by common name, which it doesn't. If you want to check the category Dogs, you need to specify that:

    http://en.wikipedia.org/w/api.php?action=query&titles=Category:Dogs&prop=categories&clcategories=Category:Mammals%20by%20common%20name