API:Exturlusage
Appearance
本页是MediaWiki Action API帮助文档的一部份。 |
MediaWiki版本: | ≥ 1.11 |
GET 请求列出链接到某个URL(例如Special:Linksearch)的页面。
API帮助文档
示例
GET请求
获取链接到slashdot.org的页面的列表
回应
{
"batchcomplete": "",
"continue": {
"eucontinue": "http://org.slashdot./|169423",
"continue": "-||"
},
"query": {
"exturlusage": [
{
"pageid": 533948,
"ns": 2,
"title": "User:Peter Ellis",
"url": "http://slashdot.org"
},
{
"pageid": 3274,
"ns": 2,
"title": "User:Alexdb",
"url": "http://slashdot.org/"
},
{
"pageid": 36471,
"ns": 2,
"title": "User:Joao",
"url": "http://slashdot.org/"
}
...
]
}
}
示例代码
Python
#!/usr/bin/python3
"""
get_exturlusage.py
MediaWiki API Demos
Demo of `Exturlusage` module: Enumerate pages that contain a given URL.
MIT License
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
"action": "query",
"format": "json",
"list": "exturlusage",
"euquery": "slashdot.org"
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
EXTURLS = DATA["query"]["exturlusage"]
for exturl in EXTURLS:
print("Page " + exturl["title"] + " has " + exturl["url"] + " url.")
PHP
<?php
/*
get_exturlusage.php
MediaWiki API Demos
Demo of `Exturlusage` module: Enumerate pages that contain a given URL.
MIT License
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "query",
"format" => "json",
"list" => "exturlusage",
"euquery" => "slashdot.org"
];
$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"]["exturlusage"] as $k => $v ) {
echo( "Page " . $v["title"] . " has " . $v["url"] . " url. \n" );
}
JavaScript
/*
get_exturlusage.js
MediaWiki API Demos
Demo of `Exturlusage` module: Enumerate pages that contain a given URL.
MIT License
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "query",
format: "json",
list: "exturlusage",
euquery: "slashdot.org"
};
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 exturls = response.query.exturlusage;
for (var exturl in exturls) {
console.log("Page " + exturls[exturl].title + " has " + exturls[exturl].url + " url.");
}
})
.catch(function(error){console.log(error);});
MediaWiki JS
/*
get_exturlusage.js
MediaWiki API Demos
Demo of `Exturlusage` module: Enumerate pages that contain a given URL.
MIT License
*/
var params = {
action: 'query',
format: 'json',
list: 'exturlusage',
euquery: 'slashdot.org'
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
var exturls = data.query.exturlusage,
exturl;
for ( exturl in exturls ) {
console.log( 'Page ' + exturls[ exturl ].title + ' has ' + exturls[ exturl ].url + ' url.' );
}
} );
可能的错误
代码 | 信息 |
---|---|
unknown_euprotocol | Wrong property for protocol parameter (use value from the list of supported protocols) |
badcontinue | 无效继续参数。您应该传递由之前查询返回的原始值。 |
参数历史
- v1.21: 启用
euexpandurl
參見
- API:Backlinks - 列出一个页面的链接。
- API:Links - 检索给定页面上的链接。
- API:Iwlinks - 在给定页面(即,元页面,特殊页面)上查找维基百科链接。
- API:Extlinks - 在给定页面上找到所有外部链接。
- API:跨语言链接 - 从给定页面获取语言链接列表。 语言链接代表翻译。
- API:Langbacklinks - 获取包含给定语言链接的页面列表。