Jump to content
MediaWiki

API:Extlinks

From mediawiki.org
This page is a translated version of the page API:Extlinks and the translation is 60% complete.
This page is part of the MediaWiki Action API documentation.
MediaWiki Action API
พื้นฐาน
การอนุมัติ
บัญชีและผู้ใช้
Page Operations
ค้นหา
Developer Utilities
Tutorials
v · d · e
เวอร์ชันมีเดียวิกิ:
≥ 1.11

GET request to get a list of all external links on the provided pages.

API documentation

The following documentation is the output of Special:ApiHelp/query+extlinks, automatically generated by the pre-release version of MediaWiki that is running on this site (MediaWiki.org).
(main | query | extlinks)

Returns all external URLs (not interwikis) from the given pages.

Specific parameters:
Other general parameters are available.
ellimit

How many links to return.

Type: integer or max
The value must be between 1 and 500.
Default: 10
elcontinue

When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.

elprotocol

Protocol of the URL. If empty and elquery is set, the protocol is http and https. Leave both this and elquery empty to list all external links.

One of the following values: Can be empty, or bitcoin, ftp, ftps, geo, git, gopher, http, https, irc, ircs, magnet, mailto, matrix, mms, news, nntp, redis, sftp, sip, sips, sms, ssh, svn, tel, telnet, urn, wikipedia, worldwind, xmpp
Default: (empty)
elquery

Search string without protocol. Useful for checking whether a certain page contains a certain external url.

elexpandurl
Deprecated.

Expand protocol-relative URLs with the canonical protocol.

Type: boolean (details)
Example:
Get a list of external links on the page MediaWiki.
api.php?action=query&prop=extlinks&titles=MediaWiki [open in sandbox]

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/"
},
...
]
}
}
}
}

รหัสตัวอย่าง

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
"""
importrequests
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
*/
varurl="https://en.wikipedia.org/w/api.php";
varparams={
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){returnresponse.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
*/
varparams={
action:'query',
titles:'Albert Einstein',
prop:'extlinks',
format:'json'
},
api=newmw.Api();
api.get(params).done(function(data){
console.log(data);
});


ประวัติพารามิเตอร์ (Parameter history)

  • v1.21: เปิดตัว elexpandurl
  • v1.18: เปิดตัว elprotocol, elquery
  • v1.13: เปิดตัว ellimit, eloffset

ดูเพิ่ม

  • API:Iwlinks - Returns all interwiki links from the given pages.
  • API:Links - Returns all links from the given pages.

AltStyle によって変換されたページ (->オリジナル) /