title: How to get count of articles in sub-sub-categories with MediaWiki API
body: <p>I want to generate an xml/json that displays the category info (count of pages and subcats) for all <strong>sub-subcategories</strong> in a specific category in Wikipedia. This requires me to parse through 2 levels in the data hierarchy, as in category > list of subcategories > list of sub-subcategories > display number of articles per sub-subcategory.</p>
  
  <p>Using wikipedia API, this gives me what I'm looking for one level of subcategories:</p>
  
  <p><a href="http://en.wikipedia.org/w/api.php?action=query&amp;format=json&amp;generator=categorymembers&amp;gcmtitle=Category:People_by_nationality_and_occupation&amp;gcmlimit=30&amp;gcmprop=ids|title&amp;prop=categoryinfo&amp;continue=" rel="nofollow">http://en.wikipedia.org/w/api.php?action=query&amp;format=json&amp;generator=categorymembers&amp;gcmtitle=Category:People_by_nationality_and_occupation&amp;gcmlimit=30&amp;gcmprop=ids|title&amp;prop=categoryinfo&amp;continue=</a></p>
  
  <p>Here's the script I'm running, which gives me dictionaries of sub-sub-categories, but I can't get page counts (categoryinfo) to show. How can I fix this?  </p>
  
  <pre><code>from wikitools import wiki, category, api
  
  def get_category_members (category_name, depth, lang='en'):
  
  articles = {}
  if depth &lt; 0:
      return articles
  
  #Begin crawling articles in category
  results = wikipedia_query({'list':'categorymembers',
                                 'cmtitle': category_name,
                                 'cmtype' : 'subcat',
                                 'cmlimit': '300',
                                 'action' : 'query',
                                 'prop' : 'categoryinfo'}, lang)
  return results
  if 'categorymembers' in results.keys() and len(results['categorymembers']) &gt; 0:
      for i, page in enumerate(results['categorymembers']):
          article = {page['title'] : 'categoryinfo'} 
          articles.update(article)
      return articles
  </code></pre>