API:Prefixsearch
| Esta página es parte de la documentación de la API de acciones de MediaWiki. |
API documentation
list=prefixsearch (ps)
Perform a prefix search for page titles. Despite the similarity in names, this module is not intended to be equivalent to Special:PrefixIndex; for that, see action=query&list=allpages with the apprefix parameter. The purpose of this module is similar to action=opensearch: to take user input and provide the best-matching titles. Depending on the search engine backend, this might include typo correction, redirect avoidance, or other heuristics. Specific parameters: Other general parameters are available.
Example:
|
Example
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
}
...
]
}
}
Sample code
prefixsearch.py
#!/usr/bin/python3
"""
prefixsearch.py
MediaWiki Action API Code Samples
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"
SEARCHTERM = "Star Wars"
PARAMS = {
'action':"query",
'list':"prefixsearch",
'pssearch':SEARCHTERM,
'format':"json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
Possible errors
| Code | Info |
|---|---|
| nopssearch | Se debe establecer el parámetro pssearch. |