Is there any API by which one can get all the categories of a page using the title or page id or url of that page? I tried searching on net but all I could find was getting dumps for specific categories. Any sort of help will be highly appreciated. Thanks
-
'I could find was getting dumps for specific categories' could you please tell where to find it? – Parag Apr 03 '17 at 04:25
2 Answers
The API you are looking for is here https://en.wikipedia.org/w/api.php This is the media wiki API and has lots of documentation.
As said above you are looking for prop=categories so... ?format=xml&action=query&prop=categories&titles=Google for example
https://en.wikipedia.org/w/api.php?format=xml&action=query&prop=categories&titles=Google
If you are looking to use this in a program it may be worth looking at the following Wikipedia page that has a series of classes and libraries for various languages to deal with handling the Wikipedia API e.t.c
Wikipedia:Creating_a_bot#Programming_languages_and_libraries

- 23,010
- 22
- 73
- 116

- 652
- 3
- 9
- 19
MediaWiki (Wikipedia's software) has an API and you can indeed do a query to get the categories of a page. For example, the following returns the categories of the page Google
in the English language Wikipedia:
https://en.wikipedia.org/w/api.php?format=xml&action=query&prop=categories&titles=Google
Note that not all categories are returned in one response. You'll see an element called query-continue
which provides additional information on how the next query should be formulated which will give you more categories.
References:

- 236,525
- 50
- 385
- 514

- 118,920
- 18
- 185
- 180
-
3It's probably better to add `cllimit=max` to the query. That way, you have smaller number of queries and you might not even need more queries (I doubt any page has more than 500 categories). – svick Mar 18 '12 at 01:20