Récupération de données dans wikipédia.
Bonjour, je souhaite utiliser l'API de wikipédia (https://fr.wikipedia.org/wiki/Sp%C3%...&explaintext=1) pour récupérer certaines données. Certaines fonctions Javascript fonctionnent mais je me trouve en face d'un problème pour récupérer une biogaraphie par exemple (extract).
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| // grab the biographie from the first search resut
function fetchBiographie(searchQuery){
const endpoint = `https://fr.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&pageids=163308&exintro=1&explaintext=1`;
fetch(endpoint)
.then(response => response.json())
.then(data => {
const result = data.query.pages;
const id = Object.keys(result)[0];
if(result[id].extract){
const biograph = result[id].extracts;
console.log(biograph);
displayBiographie(biograph);
}
})}; |
dans ma console javascript j'ai un message d'erreur sur la premiére ligne de mon fetch.
Quelqu'un pourrait il m'expliquer d'ou vient le probléme ?
Pour info cette fonction marche
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| function fetchImage(searchQuery){
const endpoint = `https://fr.wikipedia.org/w/api.php?action=query&prop=pageimages&format=json&piprop=thumbnail&pithumbsize=300&titles=${searchQuery}&origin=*`;
fetch(endpoint)
.then(response => response.json())
.then(data => {
const result = data.query.pages;
const id = Object.keys(result)[0];
if(result[id].thumbnail){
const imgURL = result[id].thumbnail.source;
console.log(imgURL);
displayImage(imgURL);
}
})}; |
Merci de votre aide