API:すべてのカテゴリ

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page API:Allcategories and the translation is 47% complete.

Other languages:
Deutsch • ‎English • ‎dansk • ‎español • ‎français • ‎polski • ‎中文 • ‎日本語
MediaWiki バージョン: 1.12

GET request to list all categories that fit certain criteria relating to their titles.

This module can be used as a generator .

APIの説明文書




list=allcategories (ac)

(main | query | allcategories)
  • This module requires read rights.
  • This module can be used as a generator.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

Enumerate all categories.

Parameters:
acfrom

The category to start enumerating from.

accontinue

When more results are available, use this to continue.

acto

The category to stop enumerating at.

acprefix

Search for all category titles that begin with this value.

acdir

Direction to sort in.

One of the following values: ascending, descending
Default: ascending
acmin

Only return categories with at least this many members.

Type: integer
acmax

Only return categories with at most this many members.

Type: integer
aclimit

How many categories to return.

No more than 500 (5,000 for bots) allowed.
Type: integer or max
Default: 10
acprop

Which properties to get:

size
Adds number of pages in the category.
hidden
Tags categories that are hidden with __HIDDENCAT__.
Values (separate with | or alternative): size, hidden
Default: (empty)
Examples:
List categories with information on the number of pages in each.
api.php?action=query&list=allcategories&acprop=size [open in sandbox]
Retrieve info about the category page itself for categories beginning List.
api.php?action=query&generator=allcategories&gacprefix=List&prop=info [open in sandbox]

GET リクエスト

Get a list of all categories, starting from "15th-century caliphs".

レスポンス

{
    {
    "batchcomplete": "",
    "continue": {
        "accontinue": "15th-century_churches_in_Denmark",
        "continue": "-||"
    },
    "query": {
        "allcategories": [
            {
                "*": "15th-century caliphs"
            },
            {
                "*": "15th-century calligraphers"
            },
            {
                "*": "15th-century card games"
            },
            ...
        ]
    }
}

サンプル コード

get_allcategories.py

#!/usr/bin/python3

"""
    get_allcategories.py

    MediaWiki Action API Code Samples
    Demo of `Allcategories` module: GET request to list all categories 
    on the English Wikipedia, starting from "15th-century caliphs".
    MIT license
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    "action":"query",
    "format":"json",
    "list":"allcategories"
    "acfrom": "15th-century caliphs"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

print(DATA)

追加的な注記

  • This module differs from list=allpages&alnamespace=14 in that categories without descriptions will be listed, while redirects and pages where the category was never used will not.
  • The response may include categories that were previously used but have since been deleted.
  • Because the response may include categories that are deleted or otherwise empty, it is recommended to filter the list using acmin=1, so as to only return categories containing one or more members.

関連項目