API:Extlinks
This page is part of the MediaWiki Action API documentation. |
MediaWiki version: | ≥ 1.11 |
GET request to get a list of all external links on the provided pages.
API documentation
Example
GET request
Get a list of external links on a page.
Response
{
"continue": {
"elcontinue": "http://ch.unibe.philosci40./lehre/winter99/einstein/Walker_S|267300440",
"continue": "||"
},
"query": {
"pages": {
"736": {
"pageid": 736,
"ns": 0,
"title": "Albert Einstein",
"extlinks": [
{
"*": "http://sedici.unlp.edu.ar/handle/10915/2785"
},
{
"*": "http://sedici.unlp.edu.ar/handle/10915/2786"
},
{
"*": "http://einstein.biz/"
},
...
]
}
}
}
}
Sample code
Python
#!/usr/bin/python3
"""
get_extlinks.py
MediaWiki API Demos
Demo of `Extlinks` module: Get a list of external links on a page
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"titles": "Albert Einstein",
"prop": "extlinks",
"format": "json"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
<?php
/*
get_extlinks.php
MediaWiki API Demos
Demo of `Extlinks` module: Get a list of external links on a page
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"titles" => "Albert Einstein",
"prop" => "extlinks",
"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 );
var_dump( $result );
JavaScript
/*
get_extlinks.js
MediaWiki API Demos
Demo of `Extlinks` module: Get a list of external links on a page
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
titles: "Albert Einstein",
prop: "extlinks",
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) {console.log(response);})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_extlinks.js
MediaWiki API Demos
Demo of `Extlinks` module: Get a list of external links on a page
MIT License
*/
var params = {
action: 'query',
titles: 'Albert Einstein',
prop: 'extlinks',
format: 'json'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
console.log( data );
} );
Parameter history
- v1.21: Introduced
elexpandurl
- v1.18: Introduced
elprotocol
,elquery
- v1.13: Introduced
ellimit
,eloffset
See also
- API:Iwlinks - Returns all interwiki links from the given pages.
- API:Links - Returns all links from the given pages.