API:Iwlinks/pl
Ta strona jest częścią dokumentacji API akcji MediaWiki. |
Wersja MediaWiki: | ≥ 1.17 |
GET request to list interwiki links from a given page.
Dokumentacja API
Przykład
Żądanie GET
Get a list of interwiki links from Albert Einstein.
Odpowiedź
{
"query": {
"pages": [
{
"pageid": 736,
"ns": 0,
"title": "Albert Einstein",
"iwlinks": [
{
"prefix": "b",
"title": "Introduction_to_Astrophysics/Albert_Einstein"
},
{
"prefix": "c",
"title": "Special:Search/Albert_Einstein"
},
{
"prefix": "commons",
"title": "Special:Search/Albert_Einstein"
},
...
]
}
]
}
}
Przykładowy kod
Python
#!/usr/bin/python3
"""
python/get_iwlinks.py
MediaWiki API Demos
Demo of `Iwlinks` module: Get the interwiki links from a given page.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"prop": "iwlinks",
"titles": "Albert Einstein"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
PAGES = DATA["query"]["pages"]
for k, v in PAGES.items():
print(v["iwlinks"])
PHP
<?php
/*
get_iwlinks.php
MediaWiki API Demos
Demo of `Iwlinks` module: Get the interwiki links from a given page.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json",
"prop" => "iwlinks",
"titles" => "Albert Einstein"
];
$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"]["pages"] as $k => $v ) {
var_dump( $v["iwlinks"] );
}
JavaScript
/*
get_iwlinks.js
MediaWiki API Demos
Demo of `Iwlinks` module: Get the interwiki links from a given page.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
prop: "iwlinks",
titles: "Albert Einstein"
};
url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});
fetch(url)
.then(function(response){return response.json();})
.then(function(response) {
var pages = response.query.pages;
for (var p in pages) {
console.log(pages[p].iwlinks);
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_iwlinks.js
MediaWiki API Demos
Demo of `Iwlinks` module: Get the interwiki links from a given page.
MIT License
*/
var params = {
action: 'query',
format: 'json',
prop: 'iwlinks',
titles: 'Albert Einstein'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var pages = data.query.pages,
p;
for ( p in pages ) {
console.log( pages[ p ].iwlinks );
}
} );
Możliwe błędy
Kod | Info |
---|---|
invalidparammix | The title parameter may only be used with prefix. |
Parameter history
- v1.24:
- Wprowadzono
iwprop
,url
- Deprecated
iwurl
- Wprowadzono
- v1.19: Wprowadzono
iwdir
- v1.18: Wprowadzono
iwprefix
,iwtitle
Zobacz też
- API:Alllinks - Lists links to a namespace.
- API:Linki - Gets links embedded on a page.
- API:Backlinks - Lists pages which link to a certain page.
- API:Linkshere - Finds all pages that link to a given page