【发布时间】:2018-02-02 13:32:50
【问题描述】:
我正在寻找此 WikiQuote 页面上的链接。我想看看“基本”类别下存在哪些子类别。它们在页面上显示为链接,因此向 API 请求链接似乎很自然。我只取回介绍中存在的“类别方案”和“主页”链接。我做错了什么/我在这里误解了什么?
代码
function httpGetAsync(theUrl, callback){
xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
callback(xmlHttp.responseText);
}
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send('null');
}
function callback(json_response){
stuff = json_response;
console.log(JSON.stringify(JSON.parse(json_response), null, 2));
}
httpGetAsync('http://en.wikiquote.org/w/api.php?action=query&prop=links&titles=Category:Fundamental&origin=*&format=json', callback);
输出
{
"batchcomplete": "",
"query": {
"pages": {
"4480": {
"pageid": 4480,
"ns": 14,
"title": "Category:Fundamental",
"links": [
{
"ns": 4,
"title": "Wikiquote:Category schemes"
},
{
"ns": 14,
"title": "Category:Main page"
}
]
}
}
}
}
【问题讨论】:
标签: javascript mediawiki mediawiki-api