dijs / wiki

Wikipedia Interface for Node.js
MIT License
315 stars 61 forks source link

mainImage() not returning the thumbnail for some pages #128

Closed udbhav-s closed 4 years ago

udbhav-s commented 4 years ago

On running

wiki().page('Microsoft').then(page => page.mainImage()).then(console.log);

it returns undefined even though the infobox in the Microsoft wikipedia article has 2 images. Is there any way to get the image?

udbhav-s commented 4 years ago

Since the image file name was in the infobox, this is the workaround I'm using:

let image = await page.mainImage();
if (!image) {
    image = 
        Object.values((await page.fullInfo()).general)
        .find(val => /.*\.(png|jpeg|jpg|svg)$/.test(val));
    if (image) image = encodeURI('https://en.wikipedia.org/wiki/Special:FilePath/' + image);
}
dijs commented 4 years ago

Great find. This is fixed in v6.0.1

dlinx commented 2 years ago

Still reproducible in v6.3.3