I am making a website that will automatically get the data from wikipedia using Wikipedia API
. What I have already tries is to use find('.infobox')
to find the infobox data.
However, I only want to get the data below the horizontal line in the infobox(starting from disease: covid in the photo below)
Here is the code I currently had:
let area = "Canada"
var url="http://en.wikipedia.org/w/api.php?action=parse&format=json&page=COVID-19_pandemic_in_"+area +"&redirects&prop=text&callback=?";
$.getJSON(url,function(data){
wikiHTML = data.parse.text["*"];
$wikiDOM = $("<document>"+wikiHTML+"</document>");
var info= $wikiDOM.find('.infobox').html();
console.log(info)
This will display all the information in the infobox.
Could anyone give me an idea or a solution that tell me how to do that?
Also, the image from wikipedia will not be able to display which will show error of invalid url
(the image area will display alt
text) Is there a way to choose not to display image before displaying which will prevent the image (alt text
) and error
in console
?
Thanks for any responds!
*In the image below, I only want to get the data from disease: Covid-19
to Vaccinations