Reputation: 6316
How can I generate a URL request like this?
var CityURL = 'https://en.wikipedia.org/w/api.php?action=query&prop=extracts&titles=boston&format=json&formatversion=2&exintro=1&callback=?';
to Group C
of a wiki like this in API
https://en.wikipedia.org/wiki/2018_AFC_Champions_League_group_stage#Group_C
I already tried this
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=?';
but not getting anything.
This is returning the first paragraph of page
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=?';
but as I said I just need the #Group_C
and the complete URL not returning anything.
$(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);
});
});
});
Upvotes: 2
Views: 923
Reputation: 81
You can use action=parse
to get the HTML of a specific section.
First you have to find out the sectionindex by calling:
https://en.wikipedia.org/w/api.php?action=parse&prop=sections&page=2018_AFC_Champions_League_group_stage&format=json&formatversion=2&callback=?
In this case the index for "Group_C" is 8.
The following URL returns the text for your desired section. Just replace parameter section
with the index number obtained by the previous request.
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=?
Upvotes: 3