Mediawiki API: How do I list all pages of a category and for each page show all of it's categories?
Asked Answered
M

1

7

I am using the following wikimedia API to list all pages with a certain category: https://www.mediawiki.org/wiki/API:Categorymembers

E.g. https://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Physics

This gives me a list of pages with title and id, but I would also like to see all categories for each page. However it seems that there is no cmprop for that.

cmprop: Which properties to get. (Default: ids|title)

    ids: Page ID
    title: Page title
    sortkey: The sortkey used for sorting in the category (hexadecimal string)
    sortkeyprefix: The sortkey prefix used for sorting in the category (human-readable part of the sortkey) 1.17+
    type: Type that the page has been categorised as (page, subcat or file) 1.17+
    timestamp: Time and date the article was added to the category

I have considered to query each page and use prop=categories to get the categories for each page, but that would mean a very large number of queries. Is there any better way of doing this?

Micromho answered 29/1, 2015 at 20:48 Comment(0)
O
8

You can use categorymembers as a generator. If you do that, you can then apply prop=categories:

https://en.wikipedia.org/w/api.php?action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=categories&cllimit=max&gcmlimit=max

Oklahoma answered 14/3, 2015 at 16:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.