如何从维基百科中获取单个段落 API
How to get a single paragraph from the Wikipedia API
如何生成这样的 URL 请求?
var CityURL = 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=boston&format=json&formatversion=2&exintro=1&callback=?';
到 Group C
API
中这样的 wiki
https://en.wikipedia.org/wiki/2018_AFC_Champions_League_group_stage#Group_C
我已经试过了
var games= 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=2018_AFC_Champions_League_group_stage#Group_C&format=json&formatversion=2&exintro=1&callback=?';
但一无所获。
这是返回页面的第一段
var games= 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=2018_AFC_Champions_League_group_stage&format=json&formatversion=2&exintro=1&callback=?';
但正如我所说,我只需要 #Group_C
和完整的 URL 不返回任何东西。
$(document).ready(function(){
var games= 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=2018_AFC_Champions_League_group_stage#Group_C&format=json&formatversion=2&exintro=1&callback=?';
$.getJSON(games,function(data) {
$.each(data.query.pages, function(i, item) {
$('div#details2').html(item.extract);
});
});
});
您可以使用 action=parse
获取特定部分的 HTML。
首先,您必须通过调用找到 sectionindex:
https://en.wikipedia.org/w/api.php?action=parse&prop=sections&page=2018_AFC_Champions_League_group_stage&format=json&formatversion=2&callback=?
在这种情况下,"Group_C" 的索引是 8。
以下 URL returns 您想要的部分的文本。将参数section
替换为上次请求得到的索引号即可
https://en.wikipedia.org/w/api.php?action=parse&prop=text&page=2018_AFC_Champions_League_group_stage§ion=8&format=json&formatversion=2&callback=?
如何生成这样的 URL 请求?
var CityURL = 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=boston&format=json&formatversion=2&exintro=1&callback=?';
到 Group C
API
https://en.wikipedia.org/wiki/2018_AFC_Champions_League_group_stage#Group_C
我已经试过了
var games= 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=2018_AFC_Champions_League_group_stage#Group_C&format=json&formatversion=2&exintro=1&callback=?';
但一无所获。
这是返回页面的第一段
var games= 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=2018_AFC_Champions_League_group_stage&format=json&formatversion=2&exintro=1&callback=?';
但正如我所说,我只需要 #Group_C
和完整的 URL 不返回任何东西。
$(document).ready(function(){
var games= 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=2018_AFC_Champions_League_group_stage#Group_C&format=json&formatversion=2&exintro=1&callback=?';
$.getJSON(games,function(data) {
$.each(data.query.pages, function(i, item) {
$('div#details2').html(item.extract);
});
});
});
您可以使用 action=parse
获取特定部分的 HTML。
首先,您必须通过调用找到 sectionindex:
https://en.wikipedia.org/w/api.php?action=parse&prop=sections&page=2018_AFC_Champions_League_group_stage&format=json&formatversion=2&callback=?
在这种情况下,"Group_C" 的索引是 8。
以下 URL returns 您想要的部分的文本。将参数section
替换为上次请求得到的索引号即可
https://en.wikipedia.org/w/api.php?action=parse&prop=text&page=2018_AFC_Champions_League_group_stage§ion=8&format=json&formatversion=2&callback=?