I was using Cheerio to find the largest image inside a webpage. Here is the code I used:
const { src } = $('img')
.map((i, el) => ({
src: el.attribs.src,
width: el.attribs.width ? Number(el.attribs.width.match(/\d+/)[0]) : -1,
}))
.toArray()
.reduce((prev, current) => (prev.width > current.width ? prev : current));
However, it works only if with width is inline for img. If there is no width I'd to set it's width to -1 and consider it in sorting
Is there any way to find the largest image in a webpage without these hacks, using Puppeteer? Since the browser is rendering these all, it can easily figure out which one is the largest