API:Prefixsearch/da
Appearance
This page is part of the MediaWiki Action API documentation. |
API dokumentation
Eksempel
GET request
Response
{
"batchcomplete": "",
"continue": {
"psoffset": 10,
"continue": "-||"
},
"query": {
"prefixsearch": [
{
"ns": 0,
"title": "Star Wars",
"pageid": 26678
},
{
"ns": 0,
"title": "Star Wars: The Last Jedi",
"pageid": 43910621
},
{
"ns": 0,
"title": "Star Wars: The Force Awakens",
"pageid": 14723194
},
{
"ns": 0,
"title": "Star Wars (film)",
"pageid": 52549
}
...
]
}
}
Eksempel kode
Python
#!/usr/bin/python3
"""
prefixsearch.py
MediaWiki API Demos
Demo of `Prefixsearch` module: Perform a prefix search for page titles
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"list": "prefixsearch",
"pssearch": "Star Wars"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
PAGES = DATA['query']['prefixsearch']
for page in PAGES:
print(page["title"])
PHP
<?php
/*
prefixsearch.php
MediaWiki API Demos
Demo of `Prefixsearch` module: Perform a prefix search for page titles
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"list" => "prefixsearch",
"pssearch" => "Star Wars",
"format" => "json"
];
$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"]["prefixsearch"] as $page ) {
echo( $page["title"] . "\n" );
}
JavaScript
/*
prefixsearch.js
MediaWiki API Demos
Demo of `Prefixsearch` module: Perform a prefix search for page titles
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
list: "prefixsearch",
pssearch: "Star Wars",
format: "json"
};
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.prefixsearch;
for (var page in pages) {
console.log( pages[page].title );
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
prefixsearch.js
MediaWiki API Demos
Demo of `Prefixsearch` module: Perform a prefix search for page titles
MIT License
*/
var params = {
action: 'query',
list: 'prefixsearch',
pssearch: 'Star Wars',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var pages = data.query.prefixsearch,
page;
for ( page in pages ) {
console.log( pages[ page ].title );
}
} );
Mulige fejl
Kode | Information |
---|---|
nopssearch | The pssearch parameter must be set. |