API:すべてのページ
Appearance
このページは MediaWiki 操作 API の説明文書の一部です。 |
MediaWiki バージョン: | ≧ 1.8 |
指定された 名前空間 内で特定の条件に合致するページをすべて列挙する GET リクエストです。
This module can be used as a generator .
APIの説明文書
例
GET リクエスト
Get all pages whose title contains the text "Jungle", in whole or part.
レスポンス
Items in the results are listed in alphabetical order, by page title.
{
"batchcomplete": "",
"continue": {
"apcontinue": "Jungle_(Bakufu_Slump_album)",
"continue": "-||"
},
"query": {
"allpages": [
{
"pageid": 341265,
"ns": 0,
"title": "Jungle"
},
{
"pageid": 56461312,
"ns": 0,
"title": "Jungle-runner"
},
{
"pageid": 18698572,
"ns": 0,
"title": "Jungle/Drum n bass"
},
{
"pageid": 1487899,
"ns": 0,
"title": "Jungle2jungle"
},
{
"pageid": 30391179,
"ns": 0,
"title": "JunglePup"
}
...
]
}
}
サンプル コード
Python
#!/usr/bin/python3
"""
get_allpages.py
MediaWiki API Demos
Demo of `Allpages` module: Get all pages whose title contains the text
"Jungle," in whole or part.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"list": "allpages",
"apfrom": "jungle",
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
PAGES = DATA["query"]["allpages"]
for page in PAGES:
print(page["title"])
PHP
<?php
/*
get_allpages.php
MediaWiki API Demos
Demo of `Allpages` module: Get all pages whose title contains the text "Jungle," in whole or part.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json",
"list" => "allpages",
"apfrom" => "jungle"
];
$url = $endPoint . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
$result = json_decode( $output, true );
foreach( $result["query"]["allpages"] as $k => $v ) {
echo( $v["title"] . "\n" );
}
JavaScript
/*
get_allpages.js
MediaWiki API Demos
Demo of `Allpages` module: Get all pages whose title contains the text "Jungle," in whole or part.
MIT License
*/
let url = "https://en.wikipedia.org/w/api.php";
const params = {
action: "query",
format: "json",
list: "allpages",
apfrom: "jungle"
}
url += "?origin=*"
Object.keys(params).forEach((key) => {
url += `&${key}=${params[key]}`
})
fetch(url)
.then((response) => {
return response.json()
})
.then((response) => {
const pages = response.query.allpages
for (let p in pages) {
console.log(pages[p].title)
}
})
.catch((error) => {
console.log(error)
})
MediaWiki JS
/*
get_allpages.js
MediaWiki API Demos
Demo of `Allpages` module: Get all pages whose title contains the text "Jungle,"
in whole or part.
MIT License
*/
var params = {
action: 'query',
format: 'json',
list: 'allpages',
apfrom: 'jungle'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var pages = data.query.allpages,
p;
for ( p in pages ) {
console.log( pages[ p ].title );
}
} );
起こりうるエラー
コード | 情報 |
---|---|
invalidparammix | The prlevel parameter may only be used with prtype. |
関連項目
- Chris G's botclasses/AllPagesBot.php — a bot that retrieves all files on a wiki, utilizing this API
- API:カテゴリのメンバー — lists all pages within a category
- API:カテゴリ — lists all categories associated with a certain page, which can aid in finding similar pages
- API:すべてのカテゴリ — lists all categories fitting a certain criteria
- API:すべての画像 — lists all images whose file names fit a certain criteria
- API:すべての利用者 — lists all users in alphabetical order