User:Martyav/Sandbox/API:Links
MediaWiki version: | ≥ 1.11 |
GET Request to find all the links on the provided page(s).
This module can be used as a generator.
API documentation
edit
prop=links (pl)
Returns all links from the given pages. Specific parameters: Other general parameters are available.
Examples:
|
Example
editGET Request
editGet a list of links from the English Wikipedia's page on en:Albert Einstein
Reponse
edit{
"query": {
"pages": [
{
"pageid": 736,
"ns": 0,
"title": "Albert Einstein",
"links": [
{
"ns": 0,
"title": "2dF Galaxy Redshift Survey"
},
{
"ns": 0,
"title": "A priori and a posteriori"
},
{
"ns": 0,
"title": "Aage Bohr"
},
{
"ns": 0,
"title": "Aarau"
},
{
"ns": 0,
"title": "Aargau"
},
...
]
}
]
}
}
Sample code
editget_links.py
#!/usr/bin/python3
"""
get_links.py
MediaWiki Action API Code Samples
Demo of `Links` module: Get all links to the given page(s)
MIT license
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"titles": "Albert Einstein",
"prop": "links"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
Parameter history
edit- v1.19: Introduced
pldir
- v1.17: Introduced
pltitles
- v1.13: Introduced
pllimit
,plcontinue
See also
edit- API:Linkshere: API:Properties submodule that finds pages which include a link to the given page.
- API:Backlinks: API:Lists submodule that gets a list of pages which link to a given page.
- API:Iwlinks: Find interwiki links on a given page (i.e, meta pages, special pages).
- API:Iwbacklinks: Get a list of pages which are linked from a given interwiki link.
- API:Extlinks: Find all external links on a given page.
- API:Exturlusage: Get all pages that link to an external URL.
- API:Langlinks: Get a list of language links from the given page. Language links represent translations.
- API:Langbacklinks Get a list of pages that contains a given language link.