H
H
HellishCode2022-01-23 15:35:52
JavaScript
HellishCode, 2022-01-23 15:35:52

How to get an image from Wikipedia?

I found information on how to do a search on the wiki,

var url = "https://en.wikipedia.org/w/api.php"; 

var params = {
    action: "query",
    list: "search",
    srsearch: "Nelson Mandela",
    format: "json"
};

url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});

fetch(url)
    .then(function(response){return response.json();})
    .then(function(response) {
        if (response.query.search[0].title === "Nelson Mandela"){
            console.log("Your search page 'Nelson Mandela' exists on English Wikipedia" );
        }
    })
    .catch(function(error){console.log(error);});

But I did not find how to get the path to the image from the search result. In order not just to save the text that comes in the response, but also the picture, if there is one in the article.
Do not tell me if there is an option to get a picture?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question