API:画像

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

Other languages:
English • ‎dansk • ‎español • ‎polski • ‎български • ‎日本語
MediaWiki バージョン: 1.11

指定したページ群に埋め込まれたメディア ファイルを列挙する GET リクエストです。

This module can be used as a generator .

APIの説明文書




prop=images (im)

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

Returns all files contained on the given pages.

Parameters:
imlimit

How many files to return.

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

When more results are available, use this to continue.

imimages

Only list these files. Useful for checking whether a certain page has a certain file.

Separate values with | or alternative. Maximum number of values is 50 (500 for bots).
imdir

The direction in which to list.

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

GET リクエスト

In the below query, we call the API to get a list of image files embedded on the English Wikipedia's page on Albert Einstein.

レスポンス

{
    "continue": {
        "imcontinue": "736|Albert_Einstein_signature_1934.svg",
        "continue": "||"
    },
    "query": {
        "pages": {
            "736": {
                "pageid": 736,
                "ns": 0,
                "title": "Albert Einstein",
                "images": [
                    {
                        "ns": 6,
                        "title": "File:1919 eclipse positive.jpg"
                    },
                    {
                        "ns": 6,
                        "title": "File:Albert Einstein's exam of maturity grades (color2).jpg"
                    },
                    {
                        "ns": 6,
                        "title": "File:Albert Einstein (Nobel).png"
                    },
                    ...
                ]
            }
        }
    }
}

サンプル コード

get_page_images.py

#!/usr/bin/python3

"""
    get_page_images.py
    MediaWiki Action API Code Samples
    Demo of `Images` module: Get all image files embedded in a
    single page.
    MIT license
"""

import requests

S = requests.Session()

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

PARAMS = {
    'action':'query',
    'format':'json',
    'prop':'images',
    'titles':'Albert Einstein'
}

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

DATA = R.json()
print(DATA)

デモ アプリ

パラメーターの履歴

  • v1.13: imcontinue, imlimit を導入しました
  • v1.18: imimages を導入しました
  • v1.19: imdir を導入しました

関連項目