Search code examples
jsonmediawikiwikipediawikipedia-apimediawiki-api

How to get the "Scientific Classification" information from Wikipedia page using API?


The article I want to query is: https://en.wikipedia.org/wiki/Aplomado_falcon

I can get the intro information and the image using their api, by entering my search term in the following format: https://en.wikipedia.org/api/rest_v1/page/summary/[my_search_term] which in my case would be: https://en.wikipedia.org/api/rest_v1/page/summary/Aplomado_falcon

This returns:

{
type: "standard",
title: "Aplomado falcon",
displaytitle: "Aplomado falcon",
namespace: {
id: 0,
text: "",
},
wikibase_item: "Q773651",
titles: {
canonical: "Aplomado_falcon",
normalized: "Aplomado falcon",
display: "Aplomado falcon",
},
pageid: 1594971,
thumbnail: {
source: "https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Aplomado_Falcon_portrait.jpg/213px-Aplomado_Falcon_portrait.jpg",
width: 213,
height: 320,
},
originalimage: {
source: "https://upload.wikimedia.org/wikipedia/commons/2/21/Aplomado_Falcon_portrait.jpg",
width: 517,
height: 775,
},
lang: "en",
dir: "ltr",
revision: "976684434",
tid: "a872bb90-f494-11ea-b097-e5e16a6eb297",
timestamp: "2020-09-04T11:10:10Z",
description: "species of falcon",
description_source: "central",
content_urls: {
desktop: {
page: "https://en.wikipedia.org/wiki/Aplomado_falcon",
revisions: "https://en.wikipedia.org/wiki/Aplomado_falcon?action=history",
edit: "https://en.wikipedia.org/wiki/Aplomado_falcon?action=edit",
talk: "https://en.wikipedia.org/wiki/Talk:Aplomado_falcon",
},
mobile: {
page: "https://en.m.wikipedia.org/wiki/Aplomado_falcon",
revisions: "https://en.m.wikipedia.org/wiki/Special:History/Aplomado_falcon",
edit: "https://en.m.wikipedia.org/wiki/Aplomado_falcon?action=edit",
talk: "https://en.m.wikipedia.org/wiki/Talk:Aplomado_falcon",
},
},
extract: "The aplomado falcon is a medium-sized falcon of the Americas. The species' largest contiguous range is in South America, but not in the deep interior Amazon Basin. It was long known as Falco fusco-coerulescens or Falco fuscocaerulescens, but these names are now believed to refer to the bat falcon. Its resemblance in shape to the hobbies accounts for its old name orange-chested hobby. Aplomado is an unusual Spanish word for "lead-colored", referring to the blue-grey areas of the plumage – an approximate English translation would be "plumbeous falcon". Spanish names for the species include halcón aplomado and halcón fajado ; in Brazil it is known as falcão-de-coleira.",
extract_html: "<p>The <b>aplomado falcon</b> is a medium-sized falcon of the Americas. The species' largest contiguous range is in South America, but not in the deep interior Amazon Basin. It was long known as <i>Falco fusco-coerulescens</i> or <i>Falco fuscocaerulescens</i>, but these names are now believed to refer to the bat falcon. Its resemblance in shape to the hobbies accounts for its old name <b>orange-chested hobby</b>. <i>Aplomado</i> is an unusual Spanish word for "lead-colored", referring to the blue-grey areas of the plumage – an approximate English translation would be "plumbeous falcon". Spanish names for the species include <i><b>halcón aplomado</b></i> and <i><b>halcón fajado</b></i> ; in Brazil it is known as <i><b>falcão-de-coleira</b></i>.</p>",
}

How do I get it to return the scientific information as well as the conservation status along with the above information via the api in json format?


Solution

  • Wikipedia's API won't provide structured data related to page content. For this type of service, check wikidata. The output of API you provided contains:

    wikibase_item: "Q773651",
    

    This is the key of wikidata entity, see https://www.wikidata.org/wiki/Q773651

    An alternative is to grab the raw Wikipedia page content and analyse template content with a custom parser.