import $ from "cheerio"; let url = 'https://wiki.openstreetmap.org/wiki/FR:Key:building:material'; let pictureDescrFinder = '.d_image img' // rp(url).then(function (html) { // getSourceOfDescriptorPageContent(html) // }) export function getSourceOfDescriptorPageContent(HTMLcontent) { const pictureDescriptionOfTagSrc = $(pictureDescrFinder, HTMLcontent) let selectedPicture = 'osm_default.jpg'; // image trouvée if (pictureDescriptionOfTagSrc[0]) { let sourcesSet = pictureDescriptionOfTagSrc[0].attribs.srcset selectedPicture = pictureDescriptionOfTagSrc[0].attribs.src; sourcesSet = sourcesSet.split(',') console.log(sourcesSet.length) // prendre l'image la plus grande du src set if (sourcesSet.length > 1) { selectedPicture = sourcesSet[sourcesSet.length - 1] selectedPicture = selectedPicture.trim().split(' ')[0] } console.log(sourcesSet) console.log(selectedPicture) return `https://wiki.openstreetmap.org${selectedPicture.trim()}`; } else { console.log("pas d'image de description dans le HTML") } }