I want to fetch an article's summary (top 2 – 3 sentences of the article). However, I am unable to do that.
I tried using :-
let name = "Maharana%20Pratap";
let baseSearchQuery = https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${name}&format=json;
function goWiki(name) {
let result = "";
let query = baseSearchQuery + name;
// $.get(query, data => console.log(data));
console.log(query);}
but I get the error message - has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
I also tried
let url = "https://en.wikipedia.org/w/api.php";
let params = {
action: "parse",
page: name,
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) {
console.log(response.parse.text["*"]);
})
.catch(function(error){console.log(error);});
this just returns text which cannot be parsed.