4

I want to query a Wikimedia Commons category and get the count of sub categories and photos in a category. For example when you look at the web page "Category:Collections of the Brooklyn Museum" in Wikimedia Commons, you get the list of subcategories.

One of the subcategories

European art in the Brooklyn Museum‎ (7 C, 301 F)

has the numbers 7 C and 301 F which means this has 7 categories and 301 images.

How do I query the Wikimedia Commons to get this category and image count information of subcategories?

I tried the following queries

http://commons.wikimedia.org/w/api.php?action=query&list=categorymembers&cmlimit=100&cmtitle=Category:Collections%20of%20the%20Brooklyn%20Museum

which gives me the category members of the category.

I can do an action render query which produces the html representation from which I can scrape the 7 C and 301 F count information.

What query can I use to get this count information without the html scraping?

Rainer Rillke
  • 1,281
  • 12
  • 24
user1881214
  • 73
  • 1
  • 8

1 Answers1

3

You can use prop=categoryinfo for this.

For example, the query:

http://commons.wikimedia.org/w/api.php?action=query&prop=categoryinfo&titles=Category:Collections%20of%20the%20Brooklyn%20Museum

returns:

<api>
  <query>
    <pages>
      <page pageid="21253813" ns="14" title="Category:Collections of the Brooklyn Museum">
        <categoryinfo size="105" pages="0" files="88" subcats="17" />
      </page>
    </pages>
  </query>
</api>
Owen Blacker
  • 4,117
  • 2
  • 33
  • 70
svick
  • 236,525
  • 50
  • 385
  • 514