3

Possible Duplicate:
How to get all article pages under a Wikipedia Category and its sub-categories

So I'm making a PHP project for fun that involves pulling out a random item from a set category on Wikipedia. For example, say I want a random weapon : my program goes to http://en.wikipedia.org/wiki/Category:Weapons and picks a sub-category at random (say Category:Toy weapons), then keeps picking a lower level of sub-category until it reaches an article that isn't a category (for example : Super Soaker).

However, I'm having problems getting a list of sub-categories from a given category. I know I can get the categories an article belongs to, but how can I do the opposite (extract the pages that have a specific category) ?

Thanks.

Community
  • 1
  • 1
Orteil
  • 439
  • 6
  • 16
  • 1
    Oh nevermind, I should have researched more thoroughly. For further reference, it's : http://www.mediawiki.org/wiki/API:Query_-_Lists#categorymembers_.2F_cm – Orteil Jan 12 '11 at 21:04
  • 4
    Watch out though, Wikpedia categories do not form a tree but a graph. There are all kinds of loops in there. You would need something a lot more complex like an ontology or human intervention to try to use it as a tree. Good luck! Also this has been asked before: http://stackoverflow.com/questions/5771745/how-to-get-all-article-pages-under-a-wikipedia-category-and-its-sub-categories – hippietrail May 20 '11 at 02:42

1 Answers1

7

you should get is using following query

api.php?action=query&list=categorymembers&cmtitle=Category:Weapons

manduki
  • 71
  • 2